执行btrace命令报错:Unable to open socket file: target process not responding or HotSpot VM not loaded
-------------------------------------------------------------------------------------------
-bash-4.1# /apps/svr/jdk7/bin/jstack/jps -l
32382 sun.tools.jps.Jps
20150 com.sun.btrace.client.Main
-------------------------------------------------------------------------------------------
-bash-4.1# /apps/svr/jdk7/bin/jstack -l 284
284: Unable to open socket file: target process not responding or HotSpot VM not loaded
-------------------------------------------------------------------------------------------
-bash-4.1# /apps/svr/jdk7/bin/jstack -J-d64 -m 284
Attaching to process ID 284, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can‘t attach to the process
-------------------------------------------------------------------------------------------
jstack报错:Unable to open socket file。是因为这个java进程的pid文件删除了
-bash-4.1# sudo -u root /apps/svr/jdk7/bin/jstack 284
284: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding
-------------------------------------------------------------------------------------------
linux操作系统为了防止/tmp目录文件过多,有个删除管理机制:tmpwatch
-bash-4.1# cat /etc/cron.daily/tmpwatch
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X ‘/tmp/hsperfdata_*‘ 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 30d "$d"
fi
done
-------------------------------------------------------------------------------------------
高版本jps、jstack不能工作原因:
这是一个从Java 6 update 21 引入的bug sunbug 7009828,在Java 6 update 25修复。
具体原因是: jdk16_21/24开始,jvm启动时产生进程号的临时文件目录优先使用-Djava.io.tmpdir指定的目录,没有指定-Djava.io.tmpdir参数才使用/tmp/hsperfdata_$USER。
正好tomcat指定了-Djava.io.tmpdir=${tomcat_home}/tmp/。而jps、jstack从/tmp/hsperfdata_$USER目录读取不到pid信息,所以才报错。