Thursday, February 17, 2011

how to kill defunct or zombie process

SkyHi @ Thursday, February 17, 2011
A “defunct” processes is also known as a “zombie” processes. A Zombie process is referred as dead process which is receding on your system thought its completed executing. In one shot we can say its a dead processes. This process will be in your process table and consuming your memory. Having more defunct process will consume your memory which intern slows your system. We have to kill the defunct process in order to free RAM and make system stable.
Why defunct process are created?Ans : When ever a process ends all the memory used by that process are cleared and assigned to new process but due to programming errors/bugs some processes are still left in process table. These are created when there is no proper communication between parent process and child process.
Some FAQ?
1. How to find a defunct process?
And : Grep defunct value in ps -ef output
#ps -ef grep defunct 

2. How can i kill a defunct process?And : Just use kill command#kill defunct-pid
 
3. Still not able to kill?

Ans : Then use kill -9 to force kill that process 
#kill -9 defunct-pid
 
4. Still have an issue in killing it?

Ans : Then try to kill its parent id and then defunct. 
#kill parent-id-of-defunct-pid
Then

#kill -9 parent-id-of-defunct-pid
 
5. Still having defunct?

Ans : If you still find defunct process eating up RAM then last and final solution is to reboot your machine.

6.What is orphan process?
Ans : An orphan process is said to be a process which runs though parent process is terminated, these process do not know what to do and when to terminate.

7. What is difference between orphan and defunct processes?Ans : A defunct process is a dead process where there is no execution happening where as orphan process is a live process which is still in execution state but don’t have parent process
I am having a system which daily creates defunct process, I cannot sit and kill these process on daily basis.

How to get rid of this problem?Ans : Just write a shell script to grep defunct process and kill them by putting this script in corntab.

Kill all process:

  1. #ps ax -o user,pid |grep 'postfix' |awk '{print $2}' |xargs -l  
  2. #ps ax -o user,pid |grep 'postfix' |awk '{print $2}' |xargs -r kill -9  
  3. #killall -9 PROCESS 


REFERENCES
http://www.linuxnix.com/2010/05/how-to-kill-defunct-or-zombie-process.html