1. 程式人生 > >Can't attach to the process: ptrace(PTRACE_ATTACH, ..)

Can't attach to the process: ptrace(PTRACE_ATTACH, ..)

信息 AC sse main PE fail eas 文檔 execute

PC : ubuntu 16.04

jdk : 1.8.0_144

當我想查看線程堆棧信息的時候,出現了如下異常:

wzy@wzy-ubuntu:~$ jstack -F 7566

××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

Attaching to process ID 7566, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can‘t attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 7566: 不允許的操作
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can‘t attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 7566: 不允許的操作
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.JStack.main(JStack.java:92)
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.jstack.JStack.runJStackTool(JStack.java:140)
at sun.tools.jstack.JStack.main(JStack.java:106)
Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can‘t attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 7566: 不允許的操作
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)

××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

解決方法:

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

原因:見參考文檔

拓展內容:ptrace_scope

參考文檔:

  1. http://gaofu1986.blog.163.com/blog/static/836012420150104137592/
  2. https://www.cnblogs.com/wscit/p/6803354.html

Can't attach to the process: ptrace(PTRACE_ATTACH, ..)