Defunct Processes

What is a defunct process ?

A defunct (or zombie) process is one whose exit status has yet to be reaped by its parent. The exit status is reaped via the wait(2), waitid(2), or waitpid(2) system call. In the normal course of system operation, zombies may occur, but are typically short-lived. This may happen if a parent exits without having reaped the exit status of some or all of its children. In that case, those children are reparented to PID 1. See init(1M), which periodically reaps such processes.

An irresponsible parent process may not exit for a very long time and thus leave zombies on the system. Since the operating system destroys nearly all components of a process before it becomes defunct, such defunct processes do not normally impact system operation. However, they do consume a small amount of system memory.

preap will attempt to prevent the administrator from unwisely reaping a child process which might soon be reaped by the parent, if:

  • The process is a child of init (1M).
  • The parent process is stopped and might wait on the child when it is again allowed to run.
  • The process has been defunct for less than one minute.

preap should be applied sparingly and only in situations in which the administrator or developer has confirmed that defunct processes will not be reaped by the parent process. Otherwise, applying preap may damage the parent process in unpredictable ways.

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.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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