本文主要是介绍pstack实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
注意,使用pstack查看系统进程的堆栈时需要sudo。
注意第一行使用的bash,不可用dash。
------------------------------------
#!/bin/bash
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/$
这篇关于pstack实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!