如何殺死defunct進程


原文: How to kill defunct process

譯者: youngsterxyf

defunct進程是指出錯損壞的進程,父子進程之間不會再通信。有時,它們會演變成“僵屍進程”,存留在你的系統中,直到系統重啟。可以嘗試 “kill -9” 命令來清除,但多數時候不管用。

為了殺死這些defunct進程,你有兩個選擇:

  • 重啟你的計算機
  • 繼續往下讀...

我們先看看系統中是否存在defunct進程:

$ ps -A | grep defunct

假設得到的輸出如下所示:

 

 ? 00:00:00 mono <defunct>
 ? 00:00:01 mono <defunct>
2 ? 00:00:00 mono <defunct>
2 ? 00:00:00 ruby <defunct>
3 ? 00:00:00 ruby <defunct>
3 ? 00:00:00 ruby <defunct>

 

這意味着存在6個defunct進程:3個mono進程,以及3個ruby進程。這些進程之所以存在,可能是因為應用程序寫得很爛或者用戶做了不常見的操作,在我這,一定是我寫的mono C#程序存在嚴重問題 :smile: 。

現在,我們來看看這些進程的ID及其父進程ID:

$ ps -ef | grep defunct | more

以上命令的輸出如下:

 

UID PID PPID ...
---------------------------------------------------------------

kenno 8328 6757 0 Mar22 ? 00:00:00 [mono] <defunct>
kenno 8522 6757 0 Mar22 ? 00:00:01 [mono] <defunct>
kenno 13132 6757 0 Mar23 ? 00:00:00 [mono] <defunct>
kenno 25822 25808 0 Mar27 ? 00:00:00 [ruby] <defunct>
kenno 28383 28366 0 Mar27 ? 00:00:00 [ruby] <defunct>
kenno 18803 18320 0 Apr02 ? 00:00:00 [ruby] <defunct>

 

  • UID:用戶ID
  • PID:進程ID
  • PPID:父進程ID

如果你使用命令 “kill -9 8328” 嘗試殺死ID為8328的進程,可能會沒效果。要想成功殺死該進程,需要對其父進程(ID為6757)執行kill命令( $ kill -9 6757 )。對所有這些進程的父進程ID應用kill命令,並驗證結果( $ ps -A | grep defunct )。

如果前一個命令顯示無結果,那么搞定!否則,可能你需要重啟一下系統。

參考文獻


譯注

執行命令 ps aux | grep defunct ,如果進程為defunct,則其第8列為 。如下所示:

work     13391  0.1  0.0      0     0 pts/0    Z    10:50   0:23 [python] <defunct>
work     13393  0.0  0.0      0     0 pts/0    Z    10:50   0:15 [python] <defunct>
work     13394  0.0  0.0      0     0 pts/0    Z    10:50   0:15 [python] <defunct>
work     13395  0.1  0.0      0     0 pts/0    Z    10:50   0:28 [python] <defunct>
work     13396  0.0  0.0      0     0 pts/0    Z    10:50   0:15 [python] <defunct>
work     13397  0.1  0.0      0     0 pts/0    Z    10:50   0:23 [python] <defunct>
work     13398  0.0  0.0      0     0 pts/0    Z    10:50   0:15 [python] <defunct>
work     13399  0.1  0.0      0     0 pts/0    Z    10:50   0:22 [python] <defunct>
work     13400  0.0  0.0      0     0 pts/0    Z    10:50   0:15 [python] <defunct>
work     13401  0.1  0.0      0     0 pts/0    Z    10:50   0:22 [python] <defunct>
work     13402  0.0  0.0      0     0 pts/0    Z    10:50   0:16 [python] <defunct>
work     13403  0.0  0.0      0     0 pts/0    Z    10:50   0:14 [python] <defunct>
work     13404  0.0  0.0      0     0 pts/0    Z    10:50   0:15 [python] <defunct>
work     13405  0.0  0.0      0     0 pts/0    Z    10:50   0:15 [python] <defunct>
work     13406  0.0  0.0      0     0 pts/0    Z    10:50   0:16 [python] <defunct>
work     13407  0.0  0.0      0     0 pts/0    Z    10:50   0:02 [python] <defunct>
work     13408  0.0  0.0      0     0 pts/0    Z    10:50   0:14 [python] <defunct>

 

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM