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)
小智 66
您可以使用以下命令通过终止其父进程来清理僵尸进程:
kill -HUP $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')
Run Code Online (Sandbox Code Playgroud)
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)
这会工作:)
小智 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)
删除僵尸.
小智 20
我试过了
kill -9 $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')
Run Code Online (Sandbox Code Playgroud)
它对我有用.
| 归档时间: |
|
| 查看次数: |
407874 次 |
| 最近记录: |