Leon Timmermans <fawaka@gmail.com> wrote: > Mentioning a problem is a good start, but what I'm missing is how to > deal with this. That is far more valuable (and probably more > complicated to do in a portable manner). I think a short piece of code using waitpid would be a good explanation. From my experience forking is most often used in daemon environments so the code below should be a good start for most people. It prevents the race condition in Eric's code and I don't see any new issues. I'd appreciate your comments on the example below. I'm going to improve my documentation changes with this: $SIG{CHLD}=sub{$child_is_gone=1;}; sub do_cleanup { do { $kid = waitpid(-1, WNOHUP); cleanup_child($kid) if $kid > 0; } while $kid > 0; } while(1){ my $pid = fork(); if ($pid == 0){ ... exit 0; } else { ... system($command); do_cleanup if $child_is_gone; } } > Also, adding it three times may be an overkill. Personally don't think > adding it to the system() documentation too adds much. You shouldn't > be thinking about this when using system(), you should when using > wait() IMO. I agree. In perlfunc a link from wait() to perlipc should suffice. so long MaikThread Previous | Thread Next