The grandchild has no parent (child exits immediately), so it gets switched over to be a subprocess of init by the scheduler.unless (fork) { # this is the child unless (fork) { # this is the grandchild # Do your request processing here ... my $exec = "/usr/local/bin/monster -i$id $filePath$file &"; qx/$exec/; exit 0; } # end grandchild # Child process just exits. exit 0; } # Parent reaps quick-exiting child. wait;
The child exits immediately, so it doesn't need to wait for its child.
The parent waits for the child, so the zombie child is cleaned up right away.
You can add all the redo logic to this relatively easily; I've left it out so as to not obscure the simplicity of the mechanism. The mainline code does wait, but since the code it's waiting on runs extremely fast, it works more like relinquishing control to the child just long enough for it to exit.
As a funny aside, this is from the Perl 4 Programming Perl.
In reply to Re: Reaping Zombies (dont wanna wait)
by pemungkah
in thread Reaping Zombies (dont wanna wait)
by seaver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |