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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:32:44  来源:igfitidea点击:

Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: cannot open binary file

javaubuntujmap

提问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

See: https://bugs.openjdk.java.net/browse/JDK-7050524

参见:https: //bugs.openjdk.java.net/browse/JDK-7050524

回答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 jpsprocess 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/javabinary and the jmap process was using .../JAVA_HOME/bin/jmapbinary.

在我们的例子中,java 进程使用.../JAVA_HOME/jre/bin/java二进制,jmap 进程使用.../JAVA_HOME/bin/jmap二进制。

Once we changed java process to use .../JAVA_HOME/bin/javabinary, 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 进程。