LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to kill <defunct> (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-kill-defunct-221154/)

sibtay 08-23-2004 12:02 AM

how to kill <defunct>
 
my ps -A gives

<application name> <defunct>

i am not able to kill it with kill command

How can i kill such a process

masand 08-23-2004 12:05 AM

hi
u can try going to the /proc directory and then
delete the directory of the name of the process

this should remove ur defunct process
depends if u r using he /proc filesystem


regards

btmiller 08-23-2004 12:25 AM

I don't think that's right ... at least I tried this on my system (Slack 10, kernel 2.6.8.1-mm2) and it didn't work, which makes sense given that /proc is just a "window" to the kernel data structures, not direct access to them. What is happening here is that on your system, a process is creating another process and then not "waiting" on its exit status. Because a process can demand the exit status of any of its children, the kernel can't totally get rid of a process until its waited upon (or until the parent exits, orphaning the process and leaving it to be adopted by init, which will clean everything up). This small snippet of Perl demonstrates this for those who are interested (this will leave one of those <defunct> processes, formally called a "zombie").

Code:

#!/usr/bin/perl

print "I am PID $$.\n";

$pid = fork();
if($pid == 0) {
  print "PID $$ about to die and become a zombie.\n";
  die;
}

while(1) {
  sleep(5);
  print "PID $$ still spinning!\n";
}

While the parent runs (which is forever until you nuke it with CTRL+C) the zombie will exist.. Zombies don't actually take up much memory since the kernel gets rid of all the processes' memory except the little bit it may need to report to the parent, should it ever decide to inquire on the exit status of its child. If you could actually clean up zombies by deleting from /proc, it would break a lot of things.

masand 08-23-2004 12:51 AM

hi
i was telling the above method since i have sen a lot of scripts and programs doing that to kill the processes,
since if we go by
#kill -9
method many of them remain there

so, what other methods do we have to kill such processes
without using
#kill
regards
gaurav

btmiller 08-23-2004 01:49 AM

I'm not sure what programs you're referring to, but trying to rm a /proc/<pid> entry on my system just results in a load of errors. A zombie process is dead, technically speaking, since it has finished executing, and thus it doesn't really make sense to kill it. The thing is that its parent hasn't waited on it, so it has to keep its entry in the process table, along with a minimal amount of information to be given to the parent if it calls wait. To get rid of the zombie, you'll probably have to kill its parent, causing the zombie to be adopted by init and cleaned up.

BTW I noticed some versions of Firefox leave a zombie netstat process lying around. Is this what you're seeing, sibtay?

jonr 08-25-2004 03:17 PM

To kill a zombie process, issue

ps anl | grep "Z"

and it will show you the zombie processes with both a PID and a PPID heading.

issue kill -9 [PPID number for the zombie process]

and the zombie process should be gone next time you do ps ax.

This kills the parent of the zombie process, as I understand it.

brassman 02-03-2005 02:36 PM

Found the explanation for the Firefox/Netstat zombie by checking Google groups. Firefox is trying to get more bits for its random number pool by calling netstat, a fairly common kludge on other OSes. Someone just messed a bit on the Linux version.

The Firefox folks are aware of the issue and promised a fix in the next release. random and urandom are more than adequate under Linux, so removing the netstat kludge is an easy fix.

jonr 02-03-2005 02:49 PM

Quote:

Originally posted by brassman
Found the explanation for the Firefox/Netstat zombie by checking Google groups. Firefox is trying to get more bits for its random number pool by calling netstat, a fairly common kludge on other OSes. Someone just messed a bit on the Linux version.

The Firefox folks are aware of the issue and promised a fix in the next release. random and urandom are more than adequate under Linux, so removing the netstat kludge is an easy fix.

That's interesting to know. Thanks for the additional info.

masand 02-04-2005 03:11 AM

Quote:

Originally posted by brassman
Found the explanation for the Firefox/Netstat zombie by checking Google groups. Firefox is trying to get more bits for its random number pool by calling netstat, a fairly common kludge on other OSes. Someone just messed a bit on the Linux version.

The Firefox folks are aware of the issue and promised a fix in the next release. random and urandom are more than adequate under Linux, so removing the netstat kludge is an easy fix.

thanks for the info but how do we go about removing that netstat kludge

regards

sriramraj 11-22-2010 03:13 AM

killing defunct process
 
There is another way to kill the defunct process. Some times killing the parent also kills the child process. Hope that will be useful for removing defunct processes.

I have tried rebooting the machine.


All times are GMT -5. The time now is 02:35 PM.