小编典典

如何杀死僵尸进程

linux

我在前台启动了我的程序(守护程序),然后用杀死了它kill -9,但剩下一个僵尸,无法用杀死它kill -9。如何杀死僵尸进程?

如果僵尸是一个死进程(已被杀死),我如何将其从输出中删除ps aux

root@OpenWrt:~# anyprogramd &
root@OpenWrt:~# ps aux | grep anyprogram
 1163 root      2552 S    anyprogramd
 1167 root      2552 S    anyprogramd
 1169 root      2552 S    anyprogramd
 1170 root      2552 S    anyprogramd
10101 root       944 S    grep anyprogram
root@OpenWrt:~# pidof anyprogramd
1170 1169 1167 1163
root@OpenWrt:~# kill -9 1170 1169 1167 1163
root@OpenWrt:~# ps aux |grep anyprogram
 1163 root         0 Z    [anyprogramd]
root@OpenWrt:~# kill -9 1163
root@OpenWrt:~# ps aux |grep anyprogram
 1163 root         0 Z    [anyprogramd]

阅读 340

收藏
2020-06-02

共1个答案

小编典典

僵尸已经死了,所以您无法杀死它。要清理僵尸,必须等待其父级等待,因此杀死父级应该可以消除僵尸。(父对象死后,僵尸将被pid 1继承,而pid
1将等待该僵尸并清除其在进程表中的条目。)如果守护程序正在生成成为僵尸的子代,则您有一个bug。您的守护程序应注意其子项何时死亡以及wait在其上死亡,以确定其退出状态。

您如何向僵尸程序的父进程的每个进程发送信号的示例(请注意,这非常粗糙,可能会杀死您不想要的进程。我不建议您使用这种大铁锤):

# Don't do this.  Incredibly risky sledge hammer!
kill $(ps -A -ostat,ppid | awk '/[zZ]/ && !a[$2]++ {print $2}')
2020-06-02