Fixing sun.jvm.hotspot.debugger.DebuggerException: Can’t attach to the process

Goal

To fix the error ‘can’t attach to the process’ while attempting to do a jinfo or jmap, for instance, to a specific Java process id

Description

From time to time, I have the need to check some information regarding a specific Java process, such as checking what memory is using or taking a heap dump. Lately, I have been facing some issues regarding the execution of the jinfo or jmap commands, as shown next

> jinfo <JAVA_PROCESS_ID> or jmap -heap:format=b <JAVA_PROCESS_ID>

which resulted in something similar to:

> Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process

Fortunately, after a search in Google, I found a solution which I am posting in my blog as a recipe for simple lookup for me in the near future. However, all credits go to the solution’s poster, not me! 🙂

How to

To fix this problem, all you have to do is execute the following command:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

And after that, you will be able to attach to the Java proces id specified.

Explanations

The solution to this problem concerns the fix of the following issues, as explained in the original solution’s blog:

  • The jmap process and the java process should be running in the same user id.
  • There is a linux ptrace bug which will prevent jmap (or jinfo) from attaching to the java process.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s