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  是执行我们脚本的意思。 

 

posted @   He_LiangLiang  阅读(363)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2020-04-18 C++基类的继承和多态
2020-04-18 TypeScript的存储器
2020-04-18 TypeScript定义一个类,以及类继承,以及虚函数,抽象基类
2020-04-18 TypeScript的函数
2020-04-18 TypeScript箭头函数(第3篇)
2020-04-18 TypeScript箭头函数(第2篇)
2020-04-18 TypeScript的箭头函数(第1篇)
点击右上角即可分享
微信分享提示