in reply to Re: open(KID, "-|") and wait()?
in thread open(KID, "-|") and wait()?
unless (fork) { # this is the child
unless (fork) { # this is the grandchild
exec "yourprogram"; # the detached process
# can also be perl code and exit(0)
} # exits when done
# Back in the child
exit 0; # immediately terminates
}
wait; # gets rid of the terminated child immediately
This works because the child process exits immediately and
is wait()ed on immediately, so no zombie. The grandchild ends up as a child of init because its parent has exited, and
init will take care of reaping the grandchild for you.
|
|---|