美文网首页
使用Java监控工具出现 Can't attach to the

使用Java监控工具出现 Can't attach to the

作者: 笨笨翔 | 来源:发表于2019-09-25 10:11 被阅读0次

    环境

    • 系统:deepin
    • jdk: 1.8

    问题日志

     li@li-PC  ~  jinfo -flags 10042    
    Picked up _JAVA_OPTIONS:   -Dawt.useSystemAAFontSettings=gasp
    Attaching to process ID 10042, please wait...
    Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process
    sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process
        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:483)
        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
        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)
    

    原因

    这是因为新版的Linux系统加入了 ptrace-scope 机制. 这种机制为了防止用户访问当前正在运行的进程的内存和状态, 而一些调试软件本身就是利用 ptrace 来进行获取某进程的内存状态的(包括GDB),所以在新版本的Linux系统, 默认情况下不允许再访问了.

    解决办法

    可以临时开启. 如:

    echo 0 > /proc/sys/kernel/yama/ptrace_scope

    永久写到文件来持久化:

    emacs /etc/sysctl.d/10-ptrace.conf
    添加或修改为以下这一句:(0:允许, 1:不允许) kernel.yama.ptrace_scope = 0

    再次执行时就可以得到结果了

     li@li-PC  ~  jinfo -flags 10042                                  
    Picked up _JAVA_OPTIONS:   -Dawt.useSystemAAFontSettings=gasp
    Attaching to process ID 10042, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.11-b03
    Non-default VM flags: -XX:InitialHeapSize=130023424 -XX:+ManagementServer -XX:MaxHeapSize=2065694720 -XX:MaxNewSize=688390144 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=1572864 -XX:OldSize=128450560 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 
    Command line:  -Djava.util.logging.config.file=/home/li/.IntelliJIdea2019.2/system/tomcat/Unnamed_basis/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:37601,suspend=y,server=n -javaagent:/home/li/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/192.5728.98/plugins/java/lib/rt/debugger-agent.jar -Dcom.sun.management.jmxremote= -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.password.file=/home/li/.IntelliJIdea2019.2/system/tomcat/Unnamed_basis/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/home/li/.IntelliJIdea2019.2/system/tomcat/Unnamed_basis/jmxremote.access -Djava.rmi.server.hostname=127.0.0.1 -Djdk.tls.ephemeralDHKeySize=2048 -Dcatalina.base=/home/li/.IntelliJIdea2019.2/system/tomcat/Unnamed_basis -Dcatalina.home=/home/li/Downloads/apache-tomcat-9.0.0.M10 -Djava.io.tmpdir=/home/li/Downloads/apache-tomcat-9.0.0.M10/temp -Dawt.useSystemAAFontSettings=gasp
    
    

    感谢nasjjsadkef

    相关文章

      网友评论

          本文标题:使用Java监控工具出现 Can't attach to the

          本文链接:https://www.haomeiwen.com/subject/cpivyctx.html