Thursday, December 20, 2007

Killing defunct (zombie) processes on Solaris - preap and orphan processes with init(1M)

A defunct (or zombie) process is one whose exit status has yet to be reaped by its parent. So when a process shows as "defunct" in ps, you need to reap it. Here's how:

preap(1) - force a defunct process to be reaped by its parent

Syntax: /usr/bin/preap PID
So, to get rid of all zombies on our system, all we have to do is script this to real all process marked as defunct:
/usr/bin/preap $(ps -ef | grep defunct | awk '{ print $2 }' | xargs)
So, what's an orphan process then? If the parent of a defunct process happens to exit, it becomes an orphan, and is asigned PID 1 as a parent - see init(1M).

Read more on zombies, defunct processes, orphans, preap and init here.

1 comments:

unix rab said...

SO GREAT - lightsaber elegance. Thanks!