在CentOS上匯出JVM記憶體資訊,centos匯出jvm記憶體
首先看下Tomcat的進程Id:
[root@iZ25Z ~]# ps aux | grep javawww 2111 4.0 23.5 1637648 452756 ? Sl 10:12 4:35 /usr/java/jdk1.7.0_80/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties ...
可以看到Tomcat的進程Id是2111, 然後用JDK內建工具jmap來匯出整個JVM 中記憶體資訊:
# jmap -dump:format=b,file=檔案名稱 [pid]jmap -dump:format=b,file=mm.hprof 2111
然而我們卻得到了這個提示:
jmap -dump:format=b,file=mm.hprof 21112111: Unable to open socket file: target process not responding or HotSpot VM not loadedThe -F option can be used when the target process is not responding
這是因為我是以root這個使用者執行的這個語句,但我的tomcat進程是以www使用者啟動並執行(用 ps aux | grep java 便能看到)。我們可以在機器上找到 /tmp/hsperfdata_$USER/$PID一個這樣的檔案,當我們執行jmap出現上述資訊時,先檢查執行該命令的使用者是否和hsperfdata_$USER這個檔案所屬的使用者一致,如果不一致,切換成一致再執行即可,或者根據提示,直接加個 -F 參數即可:
jmap -F-dump:format=b,file=mm.hprof 2111
man page對這個選項的說明是:
-F Force. Use with jmap -dump or jmap -histo option if the pid does not respond. The live suboption is not supported in this mode.
轉載請註明出處,本文地址:http://www.iiilab.com/article/6