Java: How To Get Stacktrace of Any Local / Remote Java ProcessBy Angsuman Chakraborty, Gaea News Network
Tuesday, September 23, 2008
You may run Java processes in the foreground or in many cases they may be run using cron jobs or during system startup, as background processes. How can you find out stacktraces of any running Java process? But first how can you even know their name & process id’s?
How to find process id (pid) of all running Java processes?
The following command displays list of all running Java processes in your machine -
Note the process id of the process you want to get stacktrace as you will need it in the next step.
How to find stacktrace of any running Java process?
The following command displays full stacktrace of any running Java process -
Replace <pid> with the actual pid of Java process. For example I used the following command just now to display stacktrace of DataNode (a Hadoop process) -
where 13700 happens to be the pid of the DataNode on my machine.
These commands are available in JDK 1.5 and above.
Note: jstack is an experimental tool and unsupported by Sun. The only form of jstack that is available on Windows platforms is:
jstack [-l] pid
jstack can also connect to remote Java debug server and thus print stacktraces of remote processes.
For each Java frame, the full class name, method name, ‘bci’ (byte code index) and line number, if available, are printed. With the -m option, jstack prints both Java and native frames of all threads along with the ‘pc’ (program counter). For each native frame, the closest native symbol to ‘pc’, if available, is printed. C++ mangled names are not demangled. To demangle C++ names, the output of this command may be piped to c++filt. If the given process is running on a 64-bit VM, you may need to specify the -J-d64 option.
Tags: Cases, Debugging, Java Debugging, Java Stacktrace, jps, jstack, Stacktrace