pstack命令學習

2021-08-28 22:47:34 字數 4328 閱讀 7272

pstatck命令可現實每個程序的棧跟蹤。pstack命令必須由相應程序的屬主或root執行。可以使用pstack來確定程序掛起的位置。此命令允許使用的唯一選項是要檢查的程序的pid.

例項:pstree以樹結構顯示程序

pstree -p work | grep ad

sshd(22669)---bash(22670)---ad_preprocess(4551)-+-(4552)

|-(4553)

|-(4554)

|-(4556)

`-(4557)

work為工作使用者,-p為顯示程序識別碼,ad_preprocess共啟動了6個子執行緒,加上主線程共7個執行緒。

ps -lf 4551

uid pid ppid lwp c nlwp stime tty stat time cmd

work 4551 22670 4551 2 7 16:30 pts/2 sl+ 0:02 ./ad_preprocess

work 4551 22670 4552 0 7 16:30 pts/2 sl+ 0:00 ./ad_preprocess

work 4551 22670 4553 0 7 16:30 pts/2 sl+ 0:00 ./ad_preprocess

work 4551 22670 4554 0 7 16:30 pts/2 sl+ 0:00 ./ad_preprocess

work 4551 22670 4555 0 7 16:30 pts/2 sl+ 0:00 ./ad_preprocess

work 4551 22670 4556 0 7 16:30 pts/2 sl+ 0:00 ./ad_preprocess

work 4551 22670 4557 0 7 16:30 pts/2 sl+ 0:00 ./ad_preprocess

程序共啟動了7個執行緒

pstack顯示每個程序的棧跟蹤:

pstack 4551

thread 7 (thread 1084229984 (lwp 4552)):

#0 0x000000302afc63dc in epoll_wait () from /lib64/tls/libc.so.6

#1 0x00000000006f0730 in ub::epollex::poll ()

#2 0x00000000006f172a in ub::netreactor::callback ()

#3 0x00000000006fbbbb in ub::ubtask::callback ()

#4 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#5 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#6 0x0000000000000000 in ?? ()

thread 6 (thread 1094719840 (lwp 4553)):

#0 0x000000302afc63dc in epoll_wait () from /lib64/tls/libc.so.6

#1 0x00000000006f0730 in ub::epollex::poll ()

#2 0x00000000006f172a in ub::netreactor::callback ()

#3 0x00000000006fbbbb in ub::ubtask::callback ()

#4 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#5 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#6 0x0000000000000000 in ?? ()

thread 5 (thread 1105209696 (lwp 4554)):

#0 0x000000302b80baa5 in __nanosleep_nocancel ()

#1 0x000000000079e758 in comcm::ms_sleep ()

#2 0x00000000006c8581 in ub::ubclientmanager::healthycheck ()

#3 0x00000000006c8471 in ub::ubclientmanager::start_healthy_check ()

#4 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#5 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#6 0x0000000000000000 in ?? ()

thread 4 (thread 1115699552 (lwp 4555)):

#0 0x000000302b80baa5 in __nanosleep_nocancel ()

#1 0x0000000000482b0e in armor::armor_check_thread ()

#2 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#3 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#4 0x0000000000000000 in ?? ()

thread 3 (thread 1126189408 (lwp 4556)):

#0 0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6

#1 0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6

#2 0x000000000044c972 in business_config_manager::run ()

#3 0x0000000000457b83 in thread::run_thread ()

#4 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#5 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#6 0x0000000000000000 in ?? ()

thread 2 (thread 1136679264 (lwp 4557)):

#0 0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6

#1 0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6

#2 0x00000000004524bb in process_thread::sleep_period ()

#3 0x0000000000452641 in process_thread::run ()

#4 0x0000000000457b83 in thread::run_thread ()

#5 0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#6 0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#7 0x0000000000000000 in ?? ()

thread 1 (thread 182894129792 (lwp 4551)):

#0 0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6

#1 0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6

#2 0x0000000000420d79 in ad_preprocess::run ()

#3 0x0000000000450ad0 in main ()

pstack 跟蹤程序棧

此命令可顯示每個程序的棧跟蹤。pstack 命令必須由相應程序的屬主或 root 執行。可以使用 pstack 來確定程序掛起的位置。此命令允許使用的唯一選項是要檢查的程序的 pid。請參見 proc 1 手冊頁。這個命令在排查程序問題時非常有用,比如我們發現乙個服務一直處於work狀態 如假死狀態...

Linux下檢視執行緒 pstack

需求 研發改進了某一程式,time point logger執行緒由原來的6個執行緒改為3個,需驗證是否修改了 思路 1.找到目標程式所佔的所有執行緒 2.檢視需求中所提執行緒的數量 操作 1.pstack pid 首先要找到程式對應的pid ps aux grep peer tracker pee...

Linux 下的 pstack與strace工具

pstack命令可顯示每個程序的棧跟蹤。pstack 命令必須由相應程序的屬主或 root 執行。可以使用 pstack 來確定程序掛起的位置。此命令允許使用的唯一選項是要檢查的程序的 pid。strace是乙個可用於診斷 除錯和教學的linux使用者空間 我們用它來監控使用者空間程序和核心的互動,...