1:查找cpu 使用情况 top -c
2:查看具体进程的 线程使用cpu情况 top -Hp 18884
3:watch pstack 18890 或者 pstack 18890 > a.txt
由于ubuntu 中的pstack 命令有问题 网上找了代码 另存为 mypstack
1 #!/bin/sh
2
3 if test $# -ne 1; then
4 echo "Usage: `basename $0 .sh` <process-id>" 1>&2
5 exit 1
6 fi
7
8 if test ! -r /proc/$1; then
9 echo "Process $1 not found." 1>&2
10 exit 1
11 fi
12
13 # GDB doesn't allow "thread apply all bt" when the process isn't
14 # threaded; need to peek at the process to determine if that or the
15 # simpler "bt" should be used.
16
17 backtrace="bt"
18 if test -d /proc/$1/task ; then
19 # Newer kernel; has a task/ directory.
20 if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2>/dev/null ; then
21 backtrace="thread apply all bt"
22 fi
23 elif test -f /proc/$1/maps ; then
24 # Older kernel; go by it loading libpthread.
25 if /bin/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then
26 backtrace="thread apply all bt"
27 fi
28 fi
29
30 GDB=${GDB:-/usr/bin/gdb}
31
32 if $GDB -nx --quiet --batch --readnever > /dev/null 2>&1; then
33 readnever=--readnever
34 else
35 readnever=
36 fi
37
38 # Run GDB, strip out unwanted noise.
39 $GDB --quiet $readnever -nx /proc/$1/exe $1 <<EOF 2>&1 |
40 set width 0
41 set height 0
42 set pagination no
43 $backtrace
44 EOF
45 /bin/sed -n \
46 -e 's/^\((gdb) \)*//' \
47 -e '/^#/p' \
48 -e '/^Thread/p'
49 #end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)