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

相關文章:

翻譯: