如何杀死僵尸进程

时间:2013-06-05 16:14:47

标签: linux shell ubuntu debian zombie-process

我在前台启动了我的程序(一个守护程序),然后我用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    [cwmpd]
root@OpenWrt:~# kill -9 1163
root@OpenWrt:~# ps aux |grep anyprogram
 1163 root         0 Z    [cwmpd]

7 个答案:

答案 0 :(得分:213)

一个僵尸已经死了,所以你无法杀死它。要清理僵尸,它必须由其父级等待,因此杀死父级应该可以消除僵尸。 (在父亲死后,僵尸将由pid 1继承,它会等待它并清除它在进程表中的条目。)如果你的守护进程产生了变成僵尸的孩子,你就会有一个bug。你的守护进程应该注意到它的孩子死了,并wait确定他们的退出状态。

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

kill $(ps -A -ostat,ppid | awk '/[zZ]/ && !a[$2]++ {print $2}')

答案 1 :(得分:65)

您可以使用以下命令杀死其父进程来清理僵尸进程:

kill -HUP $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')

答案 2 :(得分:31)

我试过了:

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}

这将有效:)

答案 3 :(得分:22)

http://www.linuxquestions.org/questions/suse-novell-60/howto-kill-defunct-processes-574612/

找到它

2)这是来自其他用户(Thxs Bill Dandreta)的精彩提示: 有时

kill -9 <pid>

不会杀死进程。运行

ps -xal

第4个字段是父进程,杀死所有僵尸的父母,僵尸死了!

实施例

4 0 18581 31706 17 0 2664 1236 wait S ? 0:00 sh -c /usr/bin/gcc -fomit-frame-pointer -O -mfpmat
4 0 18582 18581 17 0 2064 828 wait S ? 0:00 /usr/i686-pc-linux-gnu/gcc-bin/3.3.6/gcc -fomit-fr
4 0 18583 18582 21 0 6684 3100 - R ? 0:00 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/cc1 -quie

185811858218583是僵尸 -

kill -9 18581 18582 18583

没有效果。

kill -9 31706

移除僵尸。

答案 4 :(得分:19)

我试过

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

它对我有用。

答案 5 :(得分:0)

有时父ppid无法被杀死,因此杀死了僵尸pid

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

答案 6 :(得分:0)

在 mac 上,上述命令/说明均无效。要删除僵尸进程,您可以右键单击 docker-icon->troubleshot->clean/purge Data。

enter image description here

相关问题