java - jmap没有file参数,所以执行异常。但是添加file参数后执行正常
问题描述
具体异常信息如下:
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:/#
两个命令如下:
// error
jmap 7
// success
jmap -dump:file=test.hprof 7
爪哇资料:
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没有file参数,所以执行异常。但是添加file参数后执行正常。
解决方案
在 JDK 8 中,jmap
实际上jmap -dump
是两个不同的实用程序,被轻率地打包在一个可执行文件中。
它们服务于不同的目的,并在底层使用不同的机制:
jmap
(无参数)基于 HotSpot Serviceability Agent;jmap -dump
使用动态附加。
有关可维护性代理和动态附加的详细信息,请参阅此答案,或阅读本文。
虽然动态附加通常在大多数容器中都可以正常工作,但可服务性代理需要CAP_SYS_PTRACE
功能,该功能通常仅在特权容器中可用。
自 JDK 9 以来,这一疏忽终于得到解决,现在可服务性代理工具捆绑在一个名为jhsdb
.
推荐阅读
- neo4j - 多个 UNWIND 语句导致 Neo4j 中的错误输出
- c# - C# 如何在运行时构建动态面板
- c# - 如何递归地和反射地获取所有可能的字段名称路径的列表?
- linux - 将代码写入输出文件的更快方法
- c# - 更改 UI 图像的精灵,保留纵横比被选中但不起作用?统一2019.1.0f2
- javascript - 解决重大错误后插件(floatThead.js)不再工作
- spring - 带有安全表达式的 @Query 上的类型期望不匹配
- typescript - 我是否需要在 TypeScript 的类和接口中注释对象属性?
- java - 带有 Apache Camel 的 Spring Boot 应用程序在启动后立即关闭
- dialog - UIPath如何自动设置用户名和密码?