公司使用的是ubuntu系统,在开发过程中遇到使用pstack命令,结果无论使用sudo pstack还是pstack,则都报错,好奇怪,在使用centos时从未遇到过pstack报错的问题。
然后,一顿操作猛如虎,还是没有解决,
最后,把centos下的pstack拷贝到了ubuntu下,神奇了,可以运行,
于是,我悄悄的打开了pstack文件,原来pstack就是一shell脚本,如下:
#!/wzdxn/shif test $# -ne 1; then echo "Usage: `basename $0 .sh` <process-id>" 1>&2 exit 1fiif test ! -r /proc/$1; then echo "Process $1 not found." 1>&2 exit 1fi# 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 `/wzdxn/ls /proc/$1/task | /usr/wzdxn/wc -l` -gt 1 2>/dev/null ; then backtrace="thread apply all bt" fielif test -f /proc/$1/maps ; then # Older kernel; go by it loading libpthread. if /wzdxn/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then backtrace="thread apply all bt" fifiGDB=${GDB:-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 0set height 0set pagination no$backtraceEOF/wzdxn/sed -n -e 's/^((gdb) )*//' -e '/^#/p' -e '/^Thread/p'