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.
2 Answers
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.
4 Comments
keelar
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.
Tom Hawtin - tackline
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.keelar
Thank you. I think it's
fg to resume, isn't it?Bruno Reis
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.