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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please have you a script to find and kill zombie processes?

Status
Not open for further replies.

Pitone

Programmer
Oct 12, 2004
15
IT
Hi everybody, have you please a script to suggest me how to find and kill zombie processes?

Regards, thanks in advance

 
Have you tried a ps -ef |grep defunct
and then killed the zombie process with the kill command?

 
I have never seen anyone be able to kill a zombie process, and I don't think there is any benefit to it. A zombie process just sits around in a wait state doing nothing. The only method I have ever seen to clear zombie processes is to reboot the server, but again, since zombies don't use up any substantial resources I don't really see the point to making it much of a priority. Maybe someone else has experienced something different, but that is what I have always seen.


Jim Hirschauer
 
Thanks sirs, my question is.. I have such a situation..
when users close their session by clicking the "X" on the terminal, they don't kill all the processes forked by the shell, so I have "zombie" processes using cpu.. I need to recover their PID and kill them.
regards
 
Hmmm, a true zombie process should have a "Z" listing in when you run a ps. Maybe what you are seeing are orphaned processes that are still using resources since by definition a zombie uses no resources besides a listing in the process table. Can you provide ps output for the processes you think are the zombies?


Jim Hirschauer
 
Here is an example, the process listed is not linked to any session anymore

pintonf 442578 1 67 16:19:01 - 0:15 programnames

How can I detect these processes? and kill them?
 
Those are just orphaned processes, if you want to get rid of them, just "kill" 'em or if they do not respond: "kill -9" 'em...



HTH,

p5wizard
 
ps -ef | grep defunct | awk {' if ($2 != 1) kill -9 $1; else print "everything okay!"'}

Is this what you want?

 
You can get rid of real zombies (processes which have died, but their parent won't acknowledge that fact: the SIGCLD signal has not been received by the parent)

On AIX5 aixmibd is prone to leave zombies around.

You can find out the parent of the zombie processed from a

# ps -ef|grep defunct

output. If it is aixmibd, get rid of the zombies by stopping and restarting aixmibd:

# stopsrc -s aixmibd

(then wait while srcmstr kills aixmibd - takes longer because now aixmibd first has to acknowledge all it's zombies before terminating itself)

then restart aixmibd

# startsrc -s aixmibd

If the zombies are caused by a different process, sometimes a reboot is the only solution, because you can't go and indiscriminately kill any old process - well you can, but not without adverse effects...



HTH,

p5wizard
 
But one thing, If I want to get rid of parentless processes non linked to shell, by script? by crontab?
 
I've dealt with a similar situation, and found that the orphaned processes could be identified by examining lsof output, because they lacked stdout (file descriptor 0).

If you have lsof installed, you can check a known orphan's files with "lsof -p <pid>". If it has no entry with 0u in the FD column, this could be the way for you to identify them. The -c option was used in our case, because the orphans we were getting were all of one particular program.

I'd post the script, but process reaping is best developed on a case by case basis, with plenty of testing.


Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

 
Pitone:

I have a similar issue with users X'ing out of old Informix 4ge apps, so I have a cron job set-up to run the following afterhours:

kill -9 `ps -ef | grep rprp.4ge | awk '{print $2}'`

Works like a charm but (isn't there always a but .....) doesn't help during normal business hours
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top