Is there a way to kill a zombie process? I've tried calling exit
to kill the process and even sending SIGINT
signal to the process, but it seems that nothing can kill it. I'm programming for Linux.
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
Zombie processes are already dead, so they cannot be killed, they can only be reaped, which has to be done by their parent process via
wait*()
. This is usually called thechild reaper
idiom, in the signal handler forSIGCHLD
:See unix-faqs "How do I get rid of zombie processes that persevere?"
You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service.
You can try to kill zombie process using its pid
Please note that kill -9 does not guarantee to kill a zombie process
kill -17 ZOMBIE_PID
OR
kill -SIGCHLD ZOMBIE_PID
would possibly work, bu tlike everyone else said, it is waiting for the parent to call
wait()
so unless the parent dies without reaping, and it got stuck there for some reason you might not want to kill it.Here is a script I created to kill ALL zombie processes. It uses the GDB debugger to attach to the parent process and send a waitpid to kill the zombie process. This will leave the parent live and only slay the zombie.
GDB debugger will need to be installed and you will need to be logged in with permissions to attach to a process. This has been tested on Centos 6.3.
Enjoy.
if I recall correctly, killing the parent of a zombie process will allow the zombie process to die.
use
ps faux
to get a nice hierarchical tree of your running processes showing parent/child relationships.A zombie process is a process id (and associated termination status and resource usage information) that has not yet been waited for by its parent process. The only ways to eliminate it are to get its parent to wait for it (sometimes this can be achieved by sending
SIGCHLD
to the parent manually if the parent was just buggy and had a race condition where it missed the chance to wait) but usually you're out of luck unless you forcibly terminate the parent.Edit: Another way, if you're desperate and don't want to kill the parent, is to attach to the parent with gdb and forcibly call
waitpid
on the zombie child.