Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to kill zombie process with kill -9 [duplicate]

Tags:

linux

ubuntu

There are 2 zombie processes running in my server and I am unable to kill them with kill -9 command.

$ ps aux | awk '{ print $8 " " $2 }' | grep -w Z

Output:

Z 8511 Z 9002

Can someone please suggest me any other better way to kill them.

Thanks,

Sandeep.

like image 965
Sandeep Avatar asked Jun 28 '13 05:06

Sandeep


People also ask

How do I get rid of zombie processes?

If the parent process is still active A strace command stores all system calls and signals made by a process. Additionally, you can also kill the zombie process by sending the SIGCHLD signal to the parent process to make the parent process exit cleanly with its zombie process.

How do you reap zombie processes?

The process of eliminating zombie processes is known as 'reaping'. The simplest method is to call wait , but this will block the parent process if the child has not yet terminated. Alternatives are to use waitpid to poll or SIGCHLD to reap asynchronously.


1 Answers

Basically - you can't. And that's not necessarily a Bad Thing:

http://www.linuxsa.org.au/tips/zombies.html

Zombies are dead processes. You cannot kill the dead. All processes eventually die, and when they do they become zombies. They consume almost no resources, which is to be expected because they are dead! The reason for zombies is so the zombie's parent (process) can retrieve the zombie's exit status and resource usage statistics. The parent signals the operating system that it no longer needs the zombie by using one of the wait() system calls.

When a process dies, its child processes all become children of process number 1, which is the init process. Init is ``always'' waiting for children to die, so that they don't remain as zombies.

If you have zombie processes it means those zombies have not been waited for by their parent (look at PPID displayed by ps -l). You have three choices: Fix the parent process (make it wait); kill the parent; or live with it. Remember that living with it is not so hard because zombies take up little more than one extra line in the output of ps.

If you happen to know the parent, you can issue this command against the parent PID:

kill -s SIGCHLD pid

like image 97
paulsm4 Avatar answered Oct 13 '22 00:10

paulsm4