如何杀死僵尸进程 [英] How to kill zombie process

查看:105
本文介绍了如何杀死僵尸进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I launched my program in the foreground (a daemon program), and then I killed it with kill -9, but I get a zombie remaining and I m not able to kill it with kill -9. How to kill a zombie process?

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

If the zombie is a dead process (already killed), how I remove it from the output of 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]

推荐答案

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

A zombie is already dead, so you cannot kill it. To clean up a zombie, it must be waited on by its parent, so killing the parent should work to eliminate the zombie. (After the parent dies, the zombie will be inherited by pid 1, which will wait on it and clear its entry in the process table.) If your daemon is spawning children that become zombies, you have a bug. Your daemon should notice when its children die and wait on them to determine their exit status.

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

An example of how you might send a signal to every process that is the parent of a zombie (note that this is extremely crude and might kill processes that you do not intend. I do not recommend using this sort of sledge hammer):

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

这篇关于如何杀死僵尸进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆