如何杀死僵尸进程

MOH*_*MED 169 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]
Run Code Online (Sandbox Code Playgroud)

Wil*_*ell 231

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

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

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

  • 僵尸必须由其父母等待.找到它的父母并弄清楚为什么父母没有关注其子女,然后向社会服务部门投诉.;) (173认同)
  • 想象一下非 IT 人员来这里阅读本文。疯狂的。 (4认同)
  • 如果僵尸进程是一个死进程(已被杀死),我如何将其从“ps aux”的输出中删除? (2认同)
  • 通常,如果你是'cat/proc/<pid>/status`,你可以在`PPid`行找到父 (2认同)

小智 66

您可以使用以下命令通过终止其父进程来清理僵尸进程:

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

  • `grep`不是必需的.`ps ... | awk'/ [zZ]/{print $ 2}'` (6认同)
  • 此命令从进程表中清除僵尸,但它不会"杀死"僵尸.僵尸已经死了. (5认同)
  • AFAICS,这个命令不会杀死僵尸,而是将SIGHUP发送到它的父进程(如果它不处理SIGHUP并导致僵尸被重新分配给init,可能会杀死父进程,如前面的答案中所述).所以要小心这个命令,它可能会杀死你不期望的东西...... (2认同)

Moh*_*iee 34

我试过了:

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}
Run Code Online (Sandbox Code Playgroud)

这会工作:)

  • 不适合我. (7认同)
  • 在杀死它之前,我检查了父进程。我只是使用-9而不是-1杀死了它:kill -9 {parent id} (2认同)

小智 25

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

2)这是来自其他用户(Thxs Bill Dandreta)的一个很棒的提示:有时候

kill -9 <pid>
Run Code Online (Sandbox Code Playgroud)

不会杀死一个进程.跑

ps -xal
Run Code Online (Sandbox Code Playgroud)

第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
Run Code Online (Sandbox Code Playgroud)

18581,18582,18583是僵尸-

kill -9 18581 18582 18583
Run Code Online (Sandbox Code Playgroud)

没有效果.

kill -9 31706
Run Code Online (Sandbox Code Playgroud)

删除僵尸.

  • 好吧,刚刚为我杀了`init`,现在我什么也做不了,我被迫重启......僵尸进程是Java,从4GB内存中拿出3.4GB (2认同)

小智 20

我试过了

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

它对我有用.