2

I have such a dispatcher shell script.

while read line
do
    java TestProg $line &
done < $tasklist

On the zombie process Wikipedia page, it says

if a parent fails to call wait, the zombie will be left in the process table, causing a resource leak

in the script above I didn't use the wait function (I wrote many dispatcher shell script this way). I'm wondering if I need use wait like this so that I can prevent from zombie processes:

while read line
do
    java TestProg $line &
done < $tasklist
wait
3

I have 2 answers:

If the parent dies/ends then the processes are inherited by init. init will do it for you. So for short run processes you don't have to worry. The advice should be call wait or exit.

I think bash calls wait for you and puts the exit code somewhere.

wait only gets the exit codes, then reaps the process. A zombi uses little resource, all is freed, except a slot in the process table: the process id etc.

A zombie is dead: all of its resources are freed, except its slot in the process table. The reason that its process table slot is not freed is so that the parent can (amongst other things) get its return-code and signal a child that has just died without hitting another process that is reusing the process-identity (pid).

  • A zombie process occupies the memory, doesn't it? Besides, init is the ancestor of all process, so all the will processes be reaped by init in the long run? – Marcus Thornton Jun 17 '14 at 5:55
  • A zombie is dead, all of its resources are freed, except its slot in the process table. The reason that its process table slot is not freed is so that the parent can amongst other things, get its return code, signal a child that just died and not hit another process that is reusing the pid. – ctrl-alt-delor Jun 17 '14 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.