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.
Asked
Active
Viewed 368 times
0

keelar
- 5,814
- 7
- 40
- 79
2 Answers
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.

Tom Hawtin - tackline
- 145,806
- 30
- 211
- 305
-
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. – keelar Jun 24 '13 at 23:04
-
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. – Tom Hawtin - tackline Jun 24 '13 at 23:54
-
-
`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. – Bruno Reis Jun 25 '13 at 00:50