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 ?
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.
waiting for its children). Reaping the zombies won't make it do whatever else it should be doing. 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.