How to kill defunct process

Defunct processes are corrupted processes that can no longer communicate between the parent and child one. Sometimes, they become “zombies” and remain in your system until you reboot your machine. You can try to apply “kill -9″ command, but most of the time you’ll be out of luck.

In order to kill theses defunct processes, you have two choices:
1. Reboot your computer
2. Continue reading…

First, let’s find out if the system contains defunct process:

$ ps -A | grep defunct

Assume your output is as the following:


8328 ? 00:00:00 mono <defunct>
8522 ? 00:00:01 mono <defunct>
13132 ? 00:00:00 mono <defunct>
25822 ? 00:00:00 ruby <defunct>
28383 ? 00:00:00 ruby <defunct>
18803 ? 00:00:00 ruby <defunct>

This means you have 6 defunct processes: 3 of mono, and 3 of ruby. These processes exists because of poorly written application or unusual action taken by the user, in my case there must be some serious problem with the program I wrote in mono C# :-)

Now, let’s find the ID of the process and its parent’s:

$ ps -ef | grep defunct | more

The output from the above command:

UID PID PPID ...
---------------------------------------------------------------


kenno 8328 6757 0 Mar22 ? 00:00:00 [mono] <defunct>
kenno 8522 6757 0 Mar22 ? 00:00:01 [mono] <defunct>
kenno 13132 6757 0 Mar23 ? 00:00:00 [mono] <defunct>
kenno 25822 25808 0 Mar27 ? 00:00:00 [ruby] <defunct>
kenno 28383 28366 0 Mar27 ? 00:00:00 [ruby] <defunct>
kenno 18803 18320 0 Apr02 ? 00:00:00 [ruby] <defunct>

UID: User ID
PID: Process ID
PPID: Parent Process ID

If you try to kill the process with ID 8328 with the command “kill -9 8328″, it may not work. To properly kill it, you need to execute the kill command on its parent whose ID is 6757 ($kill -9 6757). Continue applying the kill command on all the PPID, and verify your result ($ps -A | grep defunct).

If the previous command display no result, well done, otherwise you may need to reboot your system.

Source:

http://wagoneers.com/UNIX/KILL/Kill.html

http://www.cts.wustl.edu/~allen/kill-defunct-process.html

About these ads

17 thoughts on “How to kill defunct process

  1. Patrick says:

    Is there any way to kill a defunct process without killing its parent? I have a defunct python process that opens up every time I open Deluge (python bittorrent client), and killing Deluge stops the defunct process… until the next time I open Deluge.

  2. Hi, I just found this post.

    I had the ruby defunct problem last week and the only solution we could find was to reboot, so thanks for your alternative solution.
    Now, I would really appreciate if you could help with why does this defunct problem happens?

    Kind regards

    Fernando

  3. Patrick I don’t know how to kill the defunct processes without killing their parents. I tried that with no success.

    Fernando Poblete I’m glad you found this post helpful. From my personal experience, some bad written program can cause create the defunct processes. In my case, I wrote a program using mono C# which created a lot threads. Because I was careless to take care of those threads when the main program is terminated, some of them are still alive.

    There could be other reasons, but that’s all I know.

  4. r3my says:

    1. try it with different flags ( ps -aux )
    2. try it with another program ( top )
    3. look in /var/run if there’s a pid lock file
    4. commit suicide^w^w^w^w^w^wreboot

  5. Ashay says:

    You can run the ps command with the “forest” option.

    [ For example ps faux ]

    This clearly shows the ppid for a group of processes.

  6. Pingback: Steve's Blog
  7. Tobias says:

    Hello Kenno,
    I didn’t know about that defunct thing, until today when the screen turned black.
    Thank you for the solution.
    Greetings from Germany, keep on Rocking
    Tobias

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s