I was in the process of getting the much awaited heap dump using jmap, from an ailing java process and booom !! This happens !!
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process
Well, there are two things here that needs to be taken care off.
- The jmap process and the java process ( of whose, the heap dump is being taken ) should be running in the same user id.
- There is a linux ptrace bug which will prevent jmap from attaching to the java process. To resolve this, punch in the following command before you execute the jmap heapdump command.
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
Now go ahead and execute the heapdump command using jmap.
jmap -heap:format=b <process-id>
and voila !!…You are done !! 🙂 🙂