Ahmed Moustafa <[EMAIL PROTECTED]> wrote: > From: "Bob Showalter" <[EMAIL PROTECTED]>
[ waitpid() in tight loop ] >> This example is straight out of perldoc -f waitpid, but if it's >> used "as-is", I don't see the point. Why do a non-blocking wait, >> when the do loop effectively blocks the program anyway. You only >> want non-blocking when you have something else to do. >> I would write the above as: >> >> 1 while wait != -1; # wait for all children >> >> Or am I missing something? > > All I need to do is to reap the dead processes without blocking > the program. (Also I don't want to ignore the children with using > $SIG{CHLD} = 'IGNORE';). Why not? I mean, I admire dedicated parents, but (most) *nix systems will reap them *for you* if you ignore SIGCHLD. #!/usr/bin/perl $SIG{CHLD} = 'IGNORE'; fork || exit for 1..100; sleep 2; print "waited $x\n" until ($x = wait) == -1; print "Done!\n"; If your flavor doesn't support this then you'll usually wait() in the signal handler: #!/usr/bin/perl $SIG{CHLD} = sub { wait }; ... But in general, unless you're going to do something useful with the exit status, $SIG{CHLD} = 'IGNORE' is exactly what you want. -- Steve perldoc -qa.j | perl -lpe '($_)=m("(.*)")' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]