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]

最佳答案

僵尸已经死了,所以你不能杀死它。要清理僵尸,它必须由其父级等待,因此杀死父级应该可以消除僵尸。 (在父进程死后,僵尸进程将由 pid 1 继承,它将等待它并清除进程表中的条目。)如果您的守护进程正在生成成为僵尸的子进程,那么您就有一个错误。你的守护进程应该注意到它的 child 何时死亡并wait在他们身上确定他们的退出状态。

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

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

https://stackoverflow.com/questions/16944886/

相关文章:

linux - 在远程 Linux 机器上编译 C++ - "clock skew detected

python - 如何使 Python 脚本像 Linux 中的服务或守护程序一样运行

python - 为什么在 Pylint 认为不正确的条件值中使用 len(SEQUENCE)?

python - 为什么打印到标准输出这么慢?可以提速吗?

linux - 如何在 Linux 上将所有文件夹和文件重命名为小写?

linux - 从 URL 执行 bash 脚本

python - 将数字四舍五入到最接近的整数

python - 如何在 Python 3.x 和 Python 2.x 中使用 pip

python - 是否可以在列表理解中使用 'else' ?

python - 何时使用 Tornado,何时使用 Twisted/Cyclone/GEvent/