Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

killing defunct processes 2

Status
Not open for further replies.

beksalur

Technical User
Jan 2, 2003
74
0
0
TR
is there a sh script which kills defunct processes as below.
ps -ef|grep defunc
b3scn8 1163448 1261618 0 0:00 <defunct>
b1rf6 2433140 2605082 0 0:00 <defunct>
b2rf3 2654262 1908868 3 0:00 <defunct>
b2rf1 2736222 1814664 0 0:00 <defunct>

Thanks in advance.
 
yes - shutdown :)

You have to reboot to remove defunct processes

Alex
 
but i dont want to reboot,i just want to get a sh finding defunct processes and kills them.
 
At he risk of being repetative

&quot;You have to reboot to remove defunct processes&quot;

You cannot remove them by 'kill'

If you're really concerned about them (if they are using CPU - yours appear not to be) you need to find out what is causing them in the first place. This explanation from Robert Wilson on comp.unix.aix

A <defunct> process is IBM's term for what has been traditionally known as
&quot;zombie&quot; processes (in UNIX anyway). A &quot;zombie&quot; makes more sense, since it
is literally an &quot;undead&quot; process. Specifically, a process forks a child, and
the child process completes execution before the parent. If the parent
doesn't perform a &quot;wait()&quot; on the child, the dead process will sit around in
the process table until the wait() is performed. As soon as the parent
either performs a wait(), or exits the <defunct>/zombie will go away (the
&quot;init&quot; process automatically performs a wait() on all children when the
parent dies).

<defunct> processes take up 0 (zero) system resources outside of a slot in
the process table (i.e., they do not use memory or CPU cycles). If you see
CPU cycles associated with a <defunct> process, they are probably the cycles
accumulated by the process prior to its death. If you see a <defunct>
process _still_accumulating_ CPU cycles, GET OUT OF THERE! They've come back
to life! ;-)

Alex
 
As Alex said, you can't kill defunct processes, only rebooting will get rid of them. Usually, they don't cause problems, but if you get a lot of them, they may. If these are the only defunct processes, I'd say you are probably a long way from having problems.

Take a look at this thread for more explanation of defunct processes: thread52-96153
 
A process is marked <defunct> when it has exited, but its parent has not acknowledged the fact. The PPID field in your ps listing indicates the parent process's id. If the parent is defunct, check its parent, and so forth.

Once you find an ancestor that is not defunct, exiting that process should clear out the defunct children. If that ancestor turns out to be process number 1 (/etc/init), then you will have to reboot to clear them out.



Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
There is one thing you could try, but if it is owned by init then wouldn't work, but if not owned by init then it should:

ps -eo pgid,ppid,pid,com | grep defunct
kill -6 -PGID
 
unixtechie:

Thanks for the negative pid tip. Now that I've read the kill man page more carefully, I can make a &quot;reaper&quot; script I use *much* simpler. :)

One nit and a question, though.

The nit: that final field in your format argument should be &quot;comm&quot;, rather than &quot;com&quot;, at least on AIX.

The question: Why not use the default signal (-3 SIGQUIT) first, to allow an orderly shutdown of those processes that are trapping it?


Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Hi Gurus ,

Is something wrong with my system cause I am able to kill them just with 'kill -9'. And the CPU they are using is freed.

Beksalur, here is a script I use to kill zombie processes.

ps -ef | grep defunct | awk '$9=/<defunct>/ {system (&quot;kill -9 &quot;$3)}'


Baanman
 
What I'd like to know is - What are you people running on your systems that you need a script to clear up defunct processes?

My 150 user (24x7) system has been up 55 days and has 2 defunct processes

What's causing your problems ?

Alex
 
It is because there are defunct processes owned by init and those not owned by init. The processes you are killing are not owned by init.
 
baanman, your script works because you kill the parent. the zombie's processID is $2, you are murdering $3. you also (probably inadvertently) only kill defuncts created &quot;yesterday&quot;: there is one less field in the ps -ef list for today's processes.

IBM Certified -- AIX 4.3 Obfuscation
 
#!/bin/ksh
#
pid=$1
if [[ $1 = &quot;&quot; ]]; then
echo &quot;Usage: &quot;$0&quot; pid&quot;
exit 1
fi
tmp=/tmp/$$
rm $tmp >/dev/null 2>&1
while [[ $pid != 1 ]]
do
ps -f -o'%p %P' -p $pid | tail -1 | read pid parent
echo $pid >> $tmp
pid=$parent
done
# Display header
ps gvww 1 | head -1
tail -r $tmp | while read pid ppid
do
ps gvww $pid | tail -1
done

Hope this will help .. just give the defunct process's pid and invoke the above script .. it will show it's ps tree .. then kill it accordingly.

Rgds,
vivek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top