0

Suppose I ran a java program using the java command, is it possible to get the current position or stacktrace of the this program while it is running if I have the source code of that program? A solution which does not stop my program is preferred.

0

2 Answers 2

2

jps to find the process id. jstack to dump the stack.

If it is running for the command line the ctrl-Z/ctrl-break (depending on platform) will also do the job.

Sign up to request clarification or add additional context in comments.

4 Comments

Btw, look like ctrl-Z does not work for my platform (Red Hat linux 4.1.2-51), it seems like just putting my program into background, and I found under ctrl-Z, I can't even use jstack to spy it.
Er, ctrl-3 I think was the alternative, but probably does the same? Usually ctrl-z would suspend (with bg to resume). Possibly something different is done with the signal handling.
Thank you. I think it's fg to resume, isn't it?
fg resumes on foreground, bg resumes on background. Another alternative is to issue a SIGQUIT (kill -3 [pid]), which will dump all the threads (and their stacktraces) to the STDOUT.
2

Attach a debugger to the JVM and pause the JVM. The debugger can then show you the stacktrace.

1 Comment

Thank you, but I prefer a solution not stopping my program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.