如何殺死defunct殭屍程序
阿新 • • 發佈:2019-02-07
defunct程序是指出錯損壞的程序,父子程序之間不會再通訊。有時,它們會演變成“殭屍程序”,存留在你的系統中,直到系統重啟。可以嘗試 “kill -9” 命令來清除,但多數時候不管用。
為了殺死這些defunct程序,你有兩個選擇:
- 重啟你的計算機
- 繼續往下讀...
我們先看看系統中是否存在defunct程序:
$ ps -A | grep defunct
假設得到的輸出如下所示:
8328 ? 00:00:00 mono <defunct> 8522 ? 00:00:01 mono <defunct> 13132 ? 00:00:00 mono <defunct> 25822 ? 00:00:00 ruby <defunct> 28383 ? 00:00:00 ruby <defunct> 18803 ? 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列為 Z
。如下所示:
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>