On Nov 10, 12:35 pm, shawnhco...@gmail.com (Shawn H Corey) wrote:
> C.DeRykus wrote:
> > On Nov 9, 3:31 am, shawnhco...@gmail.com (Shawn H Corey) wrote:
> >> redo if $kid != $child_pid;
>
> > Hm, I'm not sure why you'd want to 'redo' in the case of a
> > blocking wait.  As I read the docs, a blocking wait on a
> > specific pid returns only that pid if reaped normally or -1 if
> > there's no such pid  (or that pid's been already reaped). In
> > either case, I'd think you'd just want to continue processing
> > the pid loop.
>
> From `perldoc -f waitpid`:
>
> On some systems, a value of 0 indicates that there are processes still
> running.

I see that but I suspect Perl's waitpid doc is unintentionally
misleading.
A quick look at  Linux and OpenBSD wait(2) manpages specifies a 0
return can  occur only with FLAGS set to WNOHANG.

OpenBSD: from waitpid(2) manpage:

      Otherwise, if WNOHANG is specified and there
      are no stopped or exited children, 0 is returned.

 Linux:
      ... if WNOHANG was specified and no child(ren) specified by pid
      has yet changed state, then 0 is returned.


Can anyone confirm an O/S with different semantics for wait(2)'s
return...?

> In other words, waitpid can return a value which is not the pid of the
> child you requested.  Therefore redo, since it's a foreach loop.  This,
> of course, is only true on some systems; it may not be true on yours.
>

If there's a system where a blocking waitpid could return something
other than -1 or the specific pid you waited on, that'd be true. But,
even then, you'd have to be careful that a -1 indicating a reaped
process didn't cause an endless loop due to the 'redo'.


--
Charles DeRykus


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