Java 附加到进程时出错:sun.jvm.hotspot.debugger.DebuggerException:无法打开二进制文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38710457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: cannot open binary file
提问by infraio
When I use jmap to get the heap info about a process, I got error like that:
当我使用 jmap 获取有关进程的堆信息时,出现如下错误:
$jmap -heap process_id
Attaching to process ID process_id, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: cannot open binary
file
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException:
cannot open binary file
OS: Ubuntu 14.04
操作系统:Ubuntu 14.04
I have solved another error (DebuggerException: Can't attach to the process
) by updating kernel.yama.ptrace_scope = 0
.
我DebuggerException: Can't attach to the process
通过更新解决了另一个错误 ( ) kernel.yama.ptrace_scope = 0
。
回答by hakish
I faced the same issue, however when I su
'd to the correct user having the relevant permissions the issue went away.
我遇到了同样的问题,但是当我找到su
具有相关权限的正确用户时,问题就消失了。
回答by eebbesen
This will also happen if you attempt to attach to an ineligible process so it's a good idea to reconfirm your pid.
如果您尝试附加到不合格的进程,也会发生这种情况,因此最好重新确认您的 pid。
For example, a friend of mine got this when they attempted to attach to the jps
process they used to search for eligible pids ;).
例如,我的一个朋友在尝试附加到jps
他们用来搜索符合条件的 pid的进程时得到了这个;)。
回答by Ajay Kr Choudhary
Not directly related to the question asked. But, I encountered a similar error while using the jstackcommand while taking the thread dump of a java process. Let's say the pid of the java process for which I wanted thread dump is 1234.
与提出的问题没有直接关系。但是,我在获取 java 进程的线程转储时使用jstack命令时遇到了类似的错误。假设我想要线程转储的 java 进程的 pid 是 1234。
I had used the command jstack -l 1234 /home/users/a/thread-dump.txt
我用过命令 jstack -l 1234 /home/users/a/thread-dump.txt
What I missed in the above command is the redirection operator(>). The correct version of the command is
我在上面的命令中遗漏的是重定向运算符(>)。命令的正确版本是
jstack -l 1234 > /home/users/a/thread-dump.txt
Maybe it helps someone :)
也许它可以帮助某人:)
回答by user1039322
In our case, the java process was using .../JAVA_HOME/jre/bin/java
binary and the jmap process was using .../JAVA_HOME/bin/jmap
binary.
在我们的例子中,java 进程使用.../JAVA_HOME/jre/bin/java
二进制,jmap 进程使用.../JAVA_HOME/bin/jmap
二进制。
Once we changed java process to use .../JAVA_HOME/bin/java
binary, then the issue got resolved. We were able to run the jmap successfully.
一旦我们将 java 进程更改为使用.../JAVA_HOME/bin/java
二进制文件,问题就解决了。我们能够成功运行 jmap。
Key is to use run the java process using JDK java binary instead of JRE java binary.
关键是使用使用 JDK java 二进制文件而不是 JRE java 二进制文件运行 java 进程。