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 是执行我们脚本的意思。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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篇)