javasocketsjvmjstack

why jstack not working when the /tmp/.java_pid<num> socket file has been deleted


Usually, I use jstack to check if the java process is working normally. While i found, when the /tmp/java_pid<num> (the num is pid of java process) socket file has been deleted, jstack will not work. like this:

[xxx]$ jstack -l 5509

5509: 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

(PS. I didn't want to use the "-F", there may be other problems)

Is there any way to change the socket file location(not /tmp)? or to generate the socket file again when found not existed? Now what i did is to restart the java process again, a very bad solution.

Thanks!


Solution

  • /tmp/.java_pid socket is used by HotSpot Dynamic Attach mechanism. It is the way how jstack and other utilities communicate with JVM.

    You cannot change the path - it is hardcoded in JVM source code. Neither you can force JVM to regenerate it, because the Attach Listener is initialized only once in HotSpot lifetime.

    jstack -F works in a quite different way.

    In order to check whether Java process works fine, I suggest using JMX remote.

    UPDATE: as a result of JDK-8225690 fix, starting from JDK 14 / 11.0.13 / 8u332, JVM automatically re-creates .java_pid attach socket if has been deleted.