2

I will execute following command for reaping zombie

 /usr/bin/preap $(ps -ef | grep defunct | grep -v grep | awk '{ print $2 }' | xargs) 

Is there any service impact of this approach ?

2 Answers 2

4

If you reap a zombie before its parent, you lose whatever effect the reaping would have in the parent. This is obviously application-dependent.

There is very little reason to actively go and reap zombies. Some operating systems don't let you do it, short of manually ptracing the parent process and causing it to execute a waitpid system call. Solaris offers a preap utility, but the only case when you should use it is when a program is misbehaving and filling the process table with zombies.

2
  • it seems that application is misbehaving and zombie processes are only thing I am suspicious about. Commented Nov 6, 2012 at 8:40
  • @mibzer Zombie processes are probably a symptom, not the disease. Usually, zombie processes are left behind because the process that should reap them isn't doing what it should be doing (including waiting for its children). Reaping the zombies won't make it do whatever else it should be doing. Commented Nov 6, 2012 at 9:19
3

Your script might reap zombies too early preventing their parents to reap them and then causing unexpected behavior with them.

Assuming you have no way to fix the root cause of these zombie processes existence, I would only reap those that have been in the defunct state for a long enough period of time (eg. 1 minute) to avoid bypassing legitimate reaping:

for pid in $(ps -eo pid,s | nawk '$2 == "Z" {print $1 };sleep 60) do preap $pid done 

By the way, | xargs is useless in your script as a new line is a valid argument separator.

8
  • What is “too early”? What are the downsides of reaping them too soon? How to determine “long enough”? Commented Nov 5, 2012 at 12:20
  • That's a timing issue. If you happen to run your script just after a process dies, you need to let its parent process a chance to reap it and properly get its return status. Commented Nov 5, 2012 at 12:23
  • 1
    You would never know how long to wait. Better to let the parent do its job and fix it if it's not. Commented Nov 5, 2012 at 17:58
  • @Jim Paris: I agree the root cause should be fixed if possible but I assume the question means it is not possible for some reason. In any case, if the parent has not reaped a defunct child after say one minute, there is very little chance it will ever do it. Commented Nov 6, 2012 at 7:04
  • 2
    if you have zombie processes who's parent pid is '1' (init), those you can reap. If a zombie process still reports it's actual parent as it's PPID, wait it out. Commented Nov 13, 2012 at 5:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.