Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (6.1k points)

There is a daemon program launched in the foreground and then It was killed with kill -9, but a zombie is remaining and unable to be killed with kill -9. So, how to kill a zombie process?

If the zombie is a dead process, how to 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]

1 Answer

0 votes
by (11.7k points)

In Linux, A zombie process is already dead, so it cannot be killed. If you want to clean up a zombie, you need to eliminate its parent first because the zombie process must be waiting on its parent. Therefore, after the parent dies, pid 1 will inherit zombie, 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. Daemon in your system should be able to notice when its children die and wait on them to determine their exit status.

Example:

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

Browse Categories

...