Reputation: 1342
When attempting to attach an agent jar file onto another process running in java, I have came across the exception:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
I was running linux, with java Oracle JDK 8_101, however after answering this question I've realized the O.S does not matter for the cause of this problem.
Edit: Answer:
If you encounter this problem, the reason it occured for me is because I was launching a program from a different JVM, other than the default JVM specified for the system.
i.e)
Program A (The launcher), is running on JVM-1 (JDK_8_1 for example, or JDK_8_1/jdk/jre).
Program A (The launcher), creates a process with java -jar programB.jar
Program B (The target), is running on the system's default JVM, JVM-2 (JDK_8_2 for example, or JDK_8_2/jre).
Program A (The launcher) CANNOT attatch to Program B (The target), because the JVM Program A (The launcher) is running on, does not match the JVM of which Program B (The target) is running on, thus throwing the com.sun.tools.attach.AttachNotSupportedException:
Upvotes: 3
Views: 11391
Reputation: 4002
Problem: different user executing jcmd
It might happen, that the user calling jcmd is different, than the user running the proccess.
Example:
Solution:
On Linux try to run jcmd with the same user, as the process is running.
When you have such a scenario, you will get given error.
Problem: AppArmor
When AppArmor is enabled for running JVM instance, which restricts sys-calls, it might be the case, that opening a socket-connection is restricted.
Solution:
Change AppArmor-Profile for process
Upvotes: 5
Reputation: 98334
Common reasons for this problem:
/tmp/.java_pid1234
has been removed (e.g. by a scheduled job that periodically cleans up /tmp).-XX:+DisableAttachMechanism
option.Upvotes: 10