pstack
显示每个进程的栈跟踪
补充说明
pstack命令 可显示每个进程的栈跟踪。pstack 命令必须由相应进程的属主或 root 运行。可以使用 pstack 来确定进程挂起的位置。此命令允许使用的唯一选项是要检查的进程的 PID。
命令软件包下载地址:https://packages.debian.org/sid/pstack
实例
pstree以树结构显示进程
1pstree -p work | grep ad
2sshd(22669)---bash(22670)---ad_preprocess(4551)-+-{ad_preprocess}(4552)
3 |-{ad_preprocess}(4553)
4 |-{ad_preprocess}(4554)
5 |-{ad_preprocess}(4555)
6 |-{ad_preprocess}(4556)
7 `-{ad_preprocess}(4557)
work为工作用户,-p为显示进程识别码,ad_preprocess共启动了6个子线程,加上主线程共7个线程。
1ps -Lf 4551
2UID PID PPID LWP C NLWP STIME TTY stat time CMD
3work 4551 22670 4551 2 7 16:30 pts/2 Sl+ 0:02 ./ad_preprocess
4work 4551 22670 4552 0 7 16:30 pts/2 Sl+ 0:00 ./ad_preprocess
5work 4551 22670 4553 0 7 16:30 pts/2 Sl+ 0:00 ./ad_preprocess
6work 4551 22670 4554 0 7 16:30 pts/2 Sl+ 0:00 ./ad_preprocess
7work 4551 22670 4555 0 7 16:30 pts/2 Sl+ 0:00 ./ad_preprocess
8work 4551 22670 4556 0 7 16:30 pts/2 Sl+ 0:00 ./ad_preprocess
9work 4551 22670 4557 0 7 16:30 pts/2 Sl+ 0:00 ./ad_preprocess
进程共启动了7个线程
pstack显示每个进程的栈跟踪:
1pstack 4551
2Thread 7 (Thread 1084229984 (LWP 4552)):
3#0 0x000000302afc63dc in epoll_wait () from /lib64/tls/libc.so.6
4#1 0x00000000006f0730 in ub::EPollEx::poll ()
5#2 0x00000000006f172a in ub::NetReactor::callback ()
6#3 0x00000000006fbbbb in ub::UBTask::CALLBACK ()
7#4 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0
8#5 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6
9#6 0x0000000000000000 in ?? ()
10Thread 6 (Thread 1094719840 (LWP 4553)):
11#0 0x000000302afc63dc in epoll_wait () from /lib64/tls/libc.so.6
12#1 0x00000000006f0730 in ub::EPollEx::poll ()
13#2 0x00000000006f172a in ub::NetReactor::callback ()
14#3 0x00000000006fbbbb in ub::UBTask::CALLBACK ()
15#4 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0
16#5 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6
17#6 0x0000000000000000 in ?? ()
18Thread 5 (Thread 1105209696 (LWP 4554)):
19#0 0x000000302b80baa5 in __nanosleep_nocancel ()
20#1 0x000000000079e758 in comcm::ms_sleep ()
21#2 0x00000000006c8581 in ub::UbClientManager::healthyCheck ()
22#3 0x00000000006c8471 in ub::UbClientManager::start_healthy_check ()
23#4 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0
24#5 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6
25#6 0x0000000000000000 in ?? ()
26Thread 4 (Thread 1115699552 (LWP 4555)):
27#0 0x000000302b80baa5 in __nanosleep_nocancel ()
28#1 0x0000000000482b0e in armor::armor_check_thread ()
29#2 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0
30#3 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6
31#4 0x0000000000000000 in ?? ()
32Thread 3 (Thread 1126189408 (LWP 4556)):
33#0 0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6
34#1 0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6
35#2 0x000000000044c972 in Business_config_manager::run ()
36#3 0x0000000000457b83 in Thread::run_thread ()
37#4 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0
38#5 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6
39#6 0x0000000000000000 in ?? ()
40Thread 2 (Thread 1136679264 (LWP 4557)):
41#0 0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6
42#1 0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6
43#2 0x00000000004524bb in Process_thread::sleep_period ()
44#3 0x0000000000452641 in Process_thread::run ()
45#4 0x0000000000457b83 in Thread::run_thread ()
46#5 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0
47#6 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6
48#7 0x0000000000000000 in ?? ()
49Thread 1 (Thread 182894129792 (LWP 4551)):
50#0 0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6
51#1 0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6
52#2 0x0000000000420d79 in Ad_preprocess::run ()
53#3 0x0000000000450ad0 in main ()
来源:https://github.com/jaywcjlove/linux-command
最后修改于: Wednesday, January 31, 2024
版权申明:
- 未标注来源的内容全部为原创,未经授权请勿转载(因转载后排版往往错乱、内容不可控、无法持续更新等);
- 非营利为目的,演绎本博客任何内容,请以'原文出处'或者'参考链接'等方式给出本站相关网页地址(方便读者)。