get stack trace of a detached jvm
By ejannett on août 08, 2007
To get the stack trace of a running java process the usual way is to hit Ctrl-\\ on the terminal.
The jvm then print out its current state and threads'stacks.
This become a problem when the Java program is detached from the terminal as all the outputs are then discarded.
Starting to JDK5, the jstack tool is here to help or when you own the code running into the jvm and/or you can change
the way the jvm is launched an easy way is to redirect the standard streams to log file and then to send the
QUIT signal to the jvm pid.
I had to deal with another situation in which jvm was running on jdk 4 and It was not possible to change anything about it.
The trick I then used was to write a small script which catch all the write calls on stderr on the jvm .
The script use strace(1) on Linux and truss(1) on Solaris to
catch what is passed to write calls on
file descriptor 1.
This script is available here :
Here is an example of how to use it. Outputs are a little ugly but it works :-)
Once the script is launched, I send QUIT to the pid 1103.