[Linux][2010-12-31] pstack 命令

来源:互联网 发布:python官方文档pdf 编辑:程序博客网 时间:2024/06/08 01:07

1.安装

绝大数操作系统都系统pstack命令支持, 只有极少数会出现如下现象.

]# pstack
-bash: pstack: command not found

 

如果出现,请键入:]# yum install pstack

]# 为提示符, 不需要键入, 如果你不知道]# 是什么, 那你需要加油了哦! O(∩_∩)O哈哈~

 

键入后会出现如下信息,

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: centos.ustc.edu.cn
 * base: centos.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package pstack.x86_64 0:1.2-7.2.2 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================
 Package                             Arch                                Version                                 Repository                         Size
=========================================================================================================================================================
Installing:
 pstack                              x86_64                              1.2-7.2.2                               base                              4.5 k

Transaction Summary
=========================================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 4.5 k
Is this ok [y/N]: y----------------------------------------------------------此处请键入y(如果上方版本信息 和你系统一直的话)
Downloading Packages:
pstack-1.2-7.2.2.x86_64.rpm                                                                                                       | 4.5 kB     00:00    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : pstack                                                                                                                            1/1

Installed:
  pstack.x86_64 0:1.2-7.2.2                                                                                                                             

Complete!

 

 

注意: yum install 将安装最新版本, 如果你不希望安装最新版本, 请google一下.

 

pstack为shall脚本,  也可直接复制运行, 我使用yum install的原因是, 方便省事. 不用google.

 

附带pstack源码:

 

]# cat `which pstack`
#!/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}

if $GDB -nx --quiet --batch --readnever > /dev/null 2>&1; then
    readnever=--readnever
else
    readnever=
fi

# Run GDB, strip out unwanted noise.
$GDB --quiet $readnever -nx /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'

 

若果有一些符号被 "屏蔽"   "系统篡改"  请执行 cat `which pstack` 即可, `不是单引号哦!!!!!!!

 

原创粉丝点击