Pages: [1]   Go Down
Author Topic: How to kill defunct process in linux  (Read 13193 times)
Sr. Member

Karma: 0
Posts: 101

« on: September 14, 2010, 11:37:14 PM »

Many of us have faced this questions so many times. May be many of us have solved this issue too. Here, in this topic I just want to help those who were not able to sort out this issue and find it hard to kill these processes.

Sometimes when we run command

#ps ax | grep something (here I am using sh)

#ps ax | grep sh   We get below output;

11771 ?        Zs     0:00 [sh] <defunct>
14305 pts/0    S+     0:00 grep sh
26038 ?        Zs     0:00 [sh] <defunct>
23023 pts/0    Ss     0:00 -bash

and so on...

In above output we see some <defunct>, which means the process is either completed its task or has been corrupted or killed, but its child processes are still running or these parent process is monitoring its child process, hence we see these entries.

To kill this kind of process kill -9 PID don't work, we can try to kill with this command but it will show this again and again.
So we need to kill the parent process of this process.
For which we need to know, which is parent process of this defunct process. To know this we need to run below command which will show us which is the parent process of this process;

#ps -ef | grep defunct

This will give output as below;

root     11771 11764  0 Mar11 ?        00:00:00 [sh] <defunct>
root     14440 23058  0 23:14 pts/0    00:00:00 grep defunct
root     26038 26037  0 14:51 ?        00:00:00 [sh] <defunct>

In above output we can see 6 columns which are as follows;

UID       PID    PPID     C   STIME     TTY        TIME           CMD
root     11771    11764    0   Mar11      ?          00:00:00    [sh] <defunct>
root     14440    23058    0   23:14      pts/0    00:00:00    grep defunct
root     26038    26037    0   14:51      ?           00:00:00    [sh] <defunct>

I've adjusted above column to understand better. 

So now we have got parent process id from above command. Now just kill the parent process id.

# kill -9 11764 26037

And verify that now you are not getting any <defunct> process in out put of below command.

# ps ax | grep sh

Please let me know if this article was useful for you. 

Pages: [1]   Go Up
Jump to: