我在CentOS 7上运行jdk1.8.0_161 + apache-tomcat-8.0.11。
如果我以root帐号启动tomcat,我就不能对它运行jstack:
# jstack -l 1451
<It stuck, but tomcat has output in catalina.out>
# jstack -l 1451 -F
Attaching to core -F from executable 1451, please wait...
Error attaching to core file: cannot open binary file
sun.jvm.hotspot.debugger.DebuggerException: cannot open binary file
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method)
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:286)
at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:673)
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:156)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:191)
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)如果我以非root用户身份运行tomcat,jstack可以正常工作。
我试着在谷歌上搜索"sun.jvm.hotspot.debugger.DebuggerException:无法打开二进制文件“,但没有找到任何有用的东西。
有人知道发生了什么吗?
发布于 2021-04-17 19:48:51
在jstack man页面中:
The PATH environment variable needs to contain the location of the jvm.dll that is used by the
target process, or the location from which the crash dump file was produced. For example:
set PATH=<jdk>\jre\bin\client;%PATH%以root用户身份运行时,请适当设置路径。注意:默认情况下,sudo does not inherit the caller's environment variables。您可能会这样做:
$ sudo PATH=/path/to/jre/bin/whatever;$PATH jstack -l pid您还可以使用-E选项调用sudo来保留环境变量:
$ sudo -E jstack -l pidman sudo有更多信息。
https://stackoverflow.com/questions/67137566
复制相似问题