0

The specific exception information is as follows:

root@test-6cf7db85b7-sxk8h:/# jmap 7
Attaching to process ID 7, please wait...
ERROR: ptrace(PTRACE_ATTACH, ..) failed for 7: Operation not permitted
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 7: Operation not permitted
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 7: Operation not permitted
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.execute(LinuxDebuggerLocal.java:163)
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:278)
        at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:671)
        at sun.jvm.hotspot.HotSpotAgent.setupDebuggerLinux(HotSpotAgent.java:611)
        at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:337)
        at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304)
        at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:185)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.PMap.main(PMap.java:72)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.tools.jmap.JMap.runTool(JMap.java:201)
        at sun.tools.jmap.JMap.main(JMap.java:130)
Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 7: Operation not permitted
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method)
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.access$100(LinuxDebuggerLocal.java:62)
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$1AttachTask.doit(LinuxDebuggerLocal.java:269)
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.run(LinuxDebuggerLocal.java:138)

root@test-6cf7db85b7-sxk8h:/# ^C
root@test-6cf7db85b7-sxk8h:/# 

The two commands are as follows:

// error
jmap 7
// success
jmap -dump:file=test.hprof 7

java info:

openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

Jmap does not have the file parameter, so the execution is abnormal. However, the execution is normal after the file parameter is added.

  • 1
    What is this “file parameter” you repeatedly talk about? Do you mean the `-dump` parameter? – Holger Nov 02 '21 at 07:55
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 02 '21 at 08:52

1 Answers1

0

In JDK 8, jmap and jmap -dump are actually two different utilities, indiscreetly packed in one executable.

They serve different purposes, and use different mechanisms under the hood:

  • jmap (without arguments) is based on the HotSpot Serviceability Agent;
  • jmap -dump uses Dynamic Attach.

See this answer for details about Serviceability Agent and Dynamic Attach, or read this article.

While Dynamic Attach usually works fine in most containers, Serviceability Agent requires CAP_SYS_PTRACE capability, which is typically available only in a privileged container.

Since JDK 9, the oversight was finally fixed, and now Serviceability Agent tools are bundled in a separate utility named jhsdb.

apangin
  • 92,924
  • 10
  • 193
  • 247