我在前台启动了我的程序(一个守护程序),然后我用 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 -o ppid 1163
说什么?也就是说,1163的父母是谁?那是必须终止的进程。
僵尸已经死了,所以你不能杀死它。要清理僵尸,它必须由其父级等待,因此杀死父级应该可以消除僵尸。 (在父进程死后,僵尸进程将由 pid 1 继承,它将等待它并清除进程表中的条目。)如果您的守护进程正在生成成为僵尸的子进程,那么您就有一个错误。您的守护程序应注意其子代何时死亡并在其上 wait
以确定其退出状态。
一个如何向僵尸父进程的每个进程发送信号的示例(请注意,这非常粗糙,可能会杀死您不打算的进程。我不建议使用这种大锤):
# Don't do this. Incredibly risky sledge hammer!
kill $(ps -A -ostat,ppid | awk '/[zZ]/ && !a[$2]++ {print $2}')
您可以通过使用以下命令杀死其父进程来清理僵尸进程:
kill -HUP $(ps -A -ostat,ppid | awk '{/[zZ]/{ print $2 }')
grep
不是必需的。 ps ... | awk '/[zZ]/{print $2}'
我试过了:
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}
这将工作:)
在 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
18581
、18582
、18583
是僵尸 -
kill -9 18581 18582 18583
没有效果。
kill -9 31706
移除僵尸。
init
,现在我什么也做不了,不得不重新启动......僵尸进程是 Java,从 4GB 的 RAM 中占用了 3.4GB
我试过了
kill -9 $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')
它对我有用。
有时无法杀死父 ppid,因此杀死僵尸 pid
kill -9 $(ps -A -ostat,pid | awk '/[zZ]/{ print $2 }')
在 mac 上,上述命令/指令均无效。要删除僵尸进程,您可以右键单击 docker-icon->troubleshot->clean/purge Data。
https://i.stack.imgur.com/RbvIN.png
我不敢尝试以上方法。
我的解决方案是 htop 然后检测哪个进程有 multiprocessing.spawn 并 kill -9 它。
ps aux
的输出中删除它?kill $(ps -A -ostat,ppid | awk '/[zZ]/{print $2}' | sort -u)
cat /proc/<pid>/status
,您可以在PPid
行中找到父级