我在前台启动了程序(守护程序),用“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继承,pid 1将等待它并清除进程表中它的条目。)如果你的守护进程产生的孩子变成了僵尸,你就有一个bug。您的守护进程应该注意到它的子进程何时死亡,并等待它们确定它们的退出状态。

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

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

这将工作:)


您可以通过以下命令杀死僵尸进程的父进程来清除僵尸进程:

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

我试着

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

这对我很有效。


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

2)这里有一个来自另一个用户(谢谢Bill Dandreta)的好建议: 有时

kill -9 <pid>

不会终止进程。运行

ps -xal

第四个字段是父进程,杀死僵尸的所有父母和僵尸死亡!

例子

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

移除僵尸。


有时父pid不能被杀死,因此要杀死僵尸pid

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

在mac上,上面的命令/指令都不起作用。要清除僵尸进程,可以右键单击docker-icon-> troubleshoohot ->clean/purge Data。


我不敢尝试以上方法。

我的解决方案是htop,然后检测哪些进程有多进程。产卵并杀死-9它。


将这里的几个答案组合成一种优雅的方法,在杀死进程之前确认哪个进程变成僵尸进程。将脚本添加到.bashrc/。zshrc,执行killZombie命令。

killZombie() {
    pid=$(ps -A -ostat,ppid | awk '/[zZ]/ && !a[$2]++ {print $2}');
    if [ "$pid" = "" ]; then
        echo "No zombie processes found.";
    else
        cmd=$(ps -p $pid -o cmd | sed '1d');
        echo "Found zombie process PID: $pid";
        echo "$cmd";
        echo "Kill it? Return to continue… (ctrl+c to cancel)";
        read -r;
        sudo kill -9 $pid;
    fi
}