jinfo命令报错Error attaching to process 悠悠 2024-04-18 20:52 24阅读 0赞 ### 一、报错信息 ### 1.在使用jdk自带命令的时候,如jinfo ,jmap等命令,报错信息如下 Attaching to process ID 8088, please wait... Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 8088: 不允许的操作 sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 8088: 不允许的操作 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.JInfo.main(JInfo.java:138) 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.jinfo.JInfo.runTool(JInfo.java:108) at sun.tools.jinfo.JInfo.main(JInfo.java:76) Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 8088: 不允许的操作 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) ### 二、原因 ### 1.因为新版的Linux系统加入了 `ptrace-scope` 机制,该机制的目的是防止用户访问正在执行的进程的内存,但是如jinfo,jmap这些调试类工具本身就是利用`ptrace来获取执行进程的内存等信息。` ### `三、解绝` ### 1.使用:echo 0 | sudo tee /proc/sys/kernel/yama/ptrace\_scope tee:标准输出流输出到文件,意思是将0这个值输出到ptrace\_scope这个文件。 2.直接修改内核参数,参数名:kernel.yama.ptrace\_scope(值为1:表示禁止用户访问正在执行的进程的内存;0表示可以访问) 3.sysctl -n kernel.yama.ptrace\_scope:查看这个内核参数的值 4. sysctl -w kernel.yama.ptrace\_scope=0:将内核的值设为0 5.再次使用jinfo,jmap能正常使用。 ## ## ### 获取更多学习资料,面试题以及视频,关注微信公众号: ### ![20191030202900740.jpg][] [20191030202900740.jpg]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/18/92f421395485492584232001047f4003.jpg
还没有评论,来说两句吧...