Taylor, Andrew (ASPIRE) wrote:
> Am I rignt in assuming the redo should be before the $? test (in case
> this rogue pid has returned a status other than 0)?, like so:
> 
> foreach my $child_pid (@pids)
> {
>   waitpid($child_pid, 0);

Remove this line.  You are doing waitpid twice.

>   my $kid = waitpid($child_pid, 0);
> 
>   redo if $kid != $child_pid;  # So goes back to start of loop from here
> 
>   unless( 0==$? )  # And never performs this test
>   { 
>     die ("Oh No! An external process has failed!!\n");
>   }
> }
> 
> 
> That makes most sense to me but I'm not sure how to test if my
> assumption is correct.  (I'd have to somehow get the system to return a
> pid/status for a different process)

In general, you will want to test for errors as soon as possible.  If
you get an error, how do you know waitpid will ever work correctly again?

You may want to add immediately after your error test:

  last if $kid == -1;

This will exit the loop if there are no more child processes.


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to