Jstack Unable to Contact Target Process
January 16, 2019
Posted by on
In Java one of the most useful tools for diagnosing thread-related issues is jstack. It outputs a stack trace of every thread of a running process – and can also give an indication of the state of locks.
However I was getting the following error message when trying to attach jstack to a running process:
17840: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding
The solution, amazingly, was to run the jstack command as the same user as the running Java process.
The command to use for this is:
sudo -u <user> jstack -l <pid>
e.g. if the Java process is running as user “oracle” with process ID 45132 then you would execute:
sudo -u oracle jstack -l 45132