gstack查看线程信息
作者:互联网
1.查看线程信息
[upchina@iZbp14z6qodocy209yj5c8Z PriceAlarmServerGnn]$ ps -ef | grep "PriceAlarm" upchina 21261 19389 5 Apr15 ? 03:56:48 /usr/local/app/taf/tafnode/data/HQExtend.PriceAlarmServerGnn/bin/PriceAlarmServerGnn --config=/usr/local/app/taf/tafnode/data/HQExtend.PriceAlarmServerGnn/conf/HQExtend.PriceAlarmServerGnn.config.conf upchina 31896 28186 0 11:47 pts/2 00:00:00 grep --color=auto PriceAlarm
2.编写 脚本 gstack.sh ,脚本内容如下:
#!/bin/sh if test $# -ne 1; then echo "Usage: `basename $0 .sh` <process-id>" 1>&2 exit 1 fi if test ! -r /proc/$1; then echo "Process $1 not found." 1>&2 exit 1 fi # GDB doesn't allow "thread apply all bt" when the process isn't # threaded; need to peek at the process to determine if that or the # simpler "bt" should be used. backtrace="bt" if test -d /proc/$1/task ; then # Newer kernel; has a task/ directory. if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2>/dev/null ; then backtrace="thread apply all bt" fi elif test -f /proc/$1/maps ; then # Older kernel; go by it loading libpthread. if /bin/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then backtrace="thread apply all bt" fi fi GDB=${GDB:-/usr/bin/gdb} # Run GDB, strip out unwanted noise. # --readnever is no longer used since .gdb_index is now in use. $GDB --quiet -nx $GDBARGS /proc/$1/exe $1 <<EOF 2>&1 | set width 0 set height 0 set pagination no $backtrace EOF /bin/sed -n \ -e 's/^\((gdb) \)*//' \ -e '/^#/p' \ -e '/^Thread/p'
3.给脚本赋予可执行权限
chmod 755 gstack.sh
4.执行 脚本
sh gstack.sh 21261 >> a1.log
21261 是上面我们用 ps 命名查看到的进程id
>> a1.log 是将输出的字符串 重定向到 a1.log文本里面;
sh 是执行我们脚本的意思。
标签:bin,gstack,查看,bt,GDB,sh,线程,PriceAlarmServerGnn,proc 来源: https://www.cnblogs.com/music-liang/p/16159028.html