排查程式死迴圈,死鎖的方法 pstack

2021-09-20 05:27:21 字數 3469 閱讀 9654

pstack命令可顯示每個程序的棧跟蹤,pstack $pid即可,pstack命令須由$pid程序的屬主或者root執行。

這次出現cpu佔比100%的情況,但看memory佔比,並無異常,懷疑是某個地方死迴圈了。經同事提醒,用pstack命令檢視相關程序,通過執行多次pstack,發現**棧總是停在同乙個位置。具體看**,發現就是這個地方寫錯了。

這真的是個很強大的命令!和strace命令一樣強大

下面是有七個執行緒的程序的**棧列印情況

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 ()

Shell實現程式造死迴圈的幾種方法示例

前言 有時候指令碼中需要造lnfevox個死迴圈,或者讓程式一直執行下去,到某個條件方退出迴圈。對於熟悉c語言的猿人們來說,最簡單的死迴圈應該這樣寫 while 1 或者你也可以用for語程式設計客棧句和do.while語句來實現,這裡就不說了!實現方法 可是怎麼在shell指令碼中寫死迴圈呢?這個...

陣列元素奇偶排序程式中的死迴圈引起的思考

有一陣列 a 8 對該陣列進行排序使得奇數全部在偶數的前面,並且不可以引進分配新的陣列空間。看到這樣的題目,也許會覺得很簡單,因為題目的目的很明確,只要將奇數全部移到偶數的前面即可,而奇數與奇數之間 偶數與偶數之間都不要求順序。最開始我想到了如下 void sort one int a,int le...

常用的迴圈程式的設計方法

窮舉法 也成列舉法,基本思想是 首先依據題目的部分條件確定答案的大致範圍,然後對此範圍內的所有可能的情況進行逐一驗證,知道全部情況驗證完畢,若某個情況驗證符合題目條件,則為本題的乙個答案,若全部情況都驗證完後均不符合題目條件,則本題無解。百錢買白雞,這是乙個經典的不定方程求解問題。問題如下 公雞5元...