C.DeRykus wrote:
> On Feb 15, 12:35 pm, shawnhco...@gmail.com (Shawn H Corey) wrote:
>> Normally a program continues but if it is waiting or sleeping, it
>> continues after the command.  You have to redo the command until it
>> terminates correctly.  Example:  waiting for a child process:
>>
>> my $child_pid = 0;
>> WAIT_BLOCK: {
>>   $child_pid = wait();
>>   redo WAIT_BLOCK if $child_pid == 0 || $child_pid < -1;
>>
>> }
>>
> 
> No, you don't need 'redo'  on a blocking wait.  I see why you
> might conclude that  reading the waitpid doc but I believe the
> that doc is mis-leading in not clarifying that only a non-blocking
> wait, ie, WNOHANG, will potentially return a 0.

>From the man page on wait:  Otherwise they block until either a child
changes state or a signal handler interrupts the call.

The system call wait(2) does return when interrupted by a signal.  What
is not clear in the Perl documentation is whether it puts a wrapper
around the wait(2) to filter out when it returns from a signal.

So, be paranoid:  put the wait in a block and redo it until its response
is not -1 or positive.

Note that this is also true of sleep; it may return early if interrupted
by a signal.


-- 
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