今天在创建堆dump时出现了异常,Error attaching to core file: cannot open binary file
,具体的报错信息如下:
[xxxxx]# jmap 29082 -dump:live,format=b,file=aaa
Attaching to core -dump:live,format=b,file=aaa from executable 29082, 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.PMap.main(PMap.java:72)
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.jmap.JMap.runTool(JMap.java:201)
at sun.tools.jmap.JMap.main(JMap.java:130)
然后疯狂的百度了很久…没有任何答案…我一度怀疑这个版本的jdk不支持这个东西…
然后开始我的尝试,首先确认一下jmap
是否可以
嗯,貌似是没有问题,从描述信息上看,也是支持做堆dump的,那么再做一次试试,可能是我刚刚复制粘贴导致命令中夹带了某些特殊符号,好的,再来一次:
依旧失败,回过头来再看一次jmap的用法:jmap [option] <pid>
,看到没,pid是写在最后的…
所以说正确的命令应该是jmap -dump:live,format=b,file=aaa 29082
,可能没有人这么二吧,所以百度不到答案,在这里记录一下吧。
以前总是在工作中出现一些灵异诡异的问题,相同的命令、工具别人用,就一定好使,自己用的时候,就跟段誉的六脉神剑一样时灵时不灵的。现在回过头来思考,可以肯定的是,工具肯定是没问题,问题出在使用者身上,因为我没有理解或者认真读过jmap的这个说明,所以才会导致了上面的问题。其实没有诡异的问题,只有愚蠢的问题。