[英]Taking thread dump using jstack
I would like to generate an automatic thread dump. 我想生成一个自动线程转储。 This is the script I am using. 这是我正在使用的脚本。
THREADDUMP_LOG_FILE="/tmp/tmpLog_`date +"%Y%m%d%H%M%S"`"
pid=`ps axww | grep -v grep | sed -e 's/^[ ]*//g' | sed -e 's/[ ][ ]*/ /g' | cut -f1 -d' ' `
$JAVA_HOME/bin/jstack $pid >> $THREADDUMP_LOG_FILE
When I do this, this is what I see in the thread dump log file. 当我这样做时,这就是我在线程转储日志文件中看到的内容。
Usage:
jstack [-l] <pid>
(to connect to running process)
jstack -F [-m] [-l] <pid>
(to connect to a hung process)
jstack [-m] [-l] <executable> <core>
(to connect to a core file)
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server)
Options:
-F to force a thread dump. Use when jstack <pid> does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message
Clearly, I am doing something wrong. 显然,我做错了。 Can someone please guide me here on how to take a thread dump using jstack? 有人可以在这里指导我如何使用jstack进行线程转储吗?
I have no direct answer, but I assume that the shell-foo-magic you do to get the PID is perhaps wrong. 我没有直接的答案,但是我认为您为获取PID所做的shell-foo-magic可能是错误的。 Therefore could you please add an 'echo $PID' directly after the pid=... line and showus the output. 因此,您能否在pid = ...行之后直接添加“ echo $ PID”并显示输出。 Because useing directly 'jstack ' works fine for me. 因为直接使用'jstack'对我来说很好。
You can't give more than one pid to jstack, and you should give it a pid of java process only. 您不能给jstack多个pid,而应该给它一个java进程的pid。 Something like this should work: 这样的事情应该起作用:
for pid in $(ps axww | grep ' java' |grep -v grep | sed -e 's/^[ ]*//g' | sed -e 's/[ ][ ]*/ /g' | cut -f1 -d' '); do
jstack $pid >> $THREADDUMP_LOG_FILE
done
Or more simply: 或更简单地说:
for pid in $(jps | sed 's/^\([0-9][0-9]*\) .*$/\1/'); do
jstack $pid >> $THREADDUMP_LOG_FILE
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.