我在前台启动了程序(守护程序),用“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]

当前回答

我试着:

ps aux | grep -w Z   # returns the zombies pid
ps o ppid {returned pid from previous command}   # returns the parent
kill -1 {the parent id from previous command}

这将工作:)

其他回答

僵尸已经死了,所以你不能杀死它。为了清理僵尸,它必须由它的父母等待,所以杀死父母应该消除僵尸。(在父进程死亡后,僵尸进程将由pid 1继承,pid 1将等待它并清除进程表中它的条目。)如果你的守护进程产生的孩子变成了僵尸,你就有一个bug。您的守护进程应该注意到它的子进程何时死亡,并等待它们确定它们的退出状态。

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

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

在mac上,上面的命令/指令都不起作用。要清除僵尸进程,可以右键单击docker-icon-> troubleshoohot ->clean/purge Data。

我试着:

ps aux | grep -w Z   # returns the zombies pid
ps o ppid {returned pid from previous command}   # returns the parent
kill -1 {the parent id from previous command}

这将工作:)

有时父pid不能被杀死,因此要杀死僵尸pid

kill -9 $(ps -A -ostat,pid | awk '/[zZ]/{ print $2 }')

我不敢尝试以上方法。

我的解决方案是htop,然后检测哪些进程有多进程。产卵并杀死-9它。