Advertisement

001 Can't attach to the process

阅读量:

[top]

一 问题

执行jinfo -flags pid报错,错误信息如下:

复制代码
    Attaching to process ID 25985, 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
    ****

二 解决方案

执行如下命令可解决:

复制代码
    echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

再次执行命令如下:

复制代码
    **-OptiPlex-3020:~/桌面$ jinfo -flags 25985
    Attaching to process ID 25985, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.45-b02
    Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=130023424 -XX:MaxHeapSize=2069889024 -XX:MaxNewSize=689963008 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=42991616 -XX:OldSize=87031808 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC 
    Command line:

三 原因

因为ptrace-scope 机制被引入了新版Linux系统. 该机制为防止用户访问当前正在运行的进程的内存和状态, 而一些调试工具(例如GDB)本身就是利用 ptrace 来获取某进程的内存状态. 因此在新版本Linux系统中,默认情况下不再允许访问. 执行以下命令可以通过以上方法来解决问题.

四 配置到文件中

可以在文件中设置为以下内容:(允许:0, 不允许:1) kernel.yama.ptrace_scope = 0

复制代码
    vim /etc/sysctl.d/10-ptrace.conf

全部评论 (0)

还没有任何评论哟~