public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* waitpid return value when there are no children
@ 2008-01-14 17:19 Phil Endecott
       [not found] ` <1200331148207-YnoLgZYwwYtZ7UC3SA4GCMGQzZSyEchOYPYVAmT7z5s@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Endecott @ 2008-01-14 17:19 UTC (permalink / raw)
  To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

Hi Michael,

man waitpid says under RETURN VALUE:

        waitpid(): on success, returns the process ID of the child whose 
state has  changed;  on
        error,  -1  is returned; if WNOHANG was specified and no 
child(ren) specified by pid has
        yet changed state, then 0 is returned.

There is a subtle case when the child has no children at all and you 
call waitpid(-1,NULL,WNOHANG).  To me, the existing wording implies 
that it will return 0.  In fact it returns -1 and ECHILD, as I have 
discovered the hard way :-(.  The SUS documentation is more explicit 
about this, e.g. http://www.opengroup.org/onlinepubs/007908799/xsh/wait.html:

"If waitpid() was invoked with WNOHANG set in options, ****it has at 
least one child process specified by pid for which status is not 
available****, and status is not available for any process specified by 
pid, 0 will be returned. Otherwise, (pid_t)-1 will be returned, and 
errno will be set to indicate the error."

I suggest the following, which is based on your existing text:

waitpid(): on success, returns the process ID of the child whose state 
has  changed;
else if WNOHANG was specified and child(ren) specified by pid exist but 
have not yet changed state, then 0 is returned;
else an error has occurred and -1 is returned.


Regards,

Phil.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: waitpid return value when there are no children
       [not found] ` <1200331148207-YnoLgZYwwYtZ7UC3SA4GCMGQzZSyEchOYPYVAmT7z5s@public.gmane.org>
@ 2008-01-31 12:56   ` Michael Kerrisk
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk @ 2008-01-31 12:56 UTC (permalink / raw)
  To: Phil Endecott; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

Phil,

Phil Endecott wrote:
> Hi Michael,
> 
> man waitpid says under RETURN VALUE:
> 
>        waitpid(): on success, returns the process ID of the child whose
> state has  changed;  on
>        error,  -1  is returned; if WNOHANG was specified and no
> child(ren) specified by pid has
>        yet changed state, then 0 is returned.
> 
> There is a subtle case when the child has no children at all and you
> call waitpid(-1,NULL,WNOHANG).  To me, the existing wording implies that
> it will return 0.  In fact it returns -1 and ECHILD, as I have
> discovered the hard way :-(.  The SUS documentation is more explicit
> about this, e.g.
> http://www.opengroup.org/onlinepubs/007908799/xsh/wait.html:
> 
> "If waitpid() was invoked with WNOHANG set in options, ****it has at
> least one child process specified by pid for which status is not
> available****, and status is not available for any process specified by
> pid, 0 will be returned. Otherwise, (pid_t)-1 will be returned, and
> errno will be set to indicate the error."
> 
> I suggest the following, which is based on your existing text:
> 
> waitpid(): on success, returns the process ID of the child whose state
> has  changed;
> else if WNOHANG was specified and child(ren) specified by pid exist but
> have not yet changed state, then 0 is returned;
> else an error has occurred and -1 is returned.

You are of course right that the text could be clearer.  Thanks for
pointing that out.

For man-pages-2.77, I've changed the text to:

       waitpid(): on success, returns  the  process  ID  of  the
       child  whose  state has changed; if WNOHANG was specified
       and one or more child(ren) specified by  pid  exist,  but
       have  not  yet  changed  state,  then  0 is returned.  On
       error, -1 is returned.

Cheers,

Michael

-- 
Michael Kerrisk
Maintainer of the Linux man-pages project
http://www.kernel.org/doc/man-pages/
Want to report a man-pages bug?  Look here:
http://www.kernel.org/doc/man-pages/reporting_bugs.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-01-31 12:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-14 17:19 waitpid return value when there are no children Phil Endecott
     [not found] ` <1200331148207-YnoLgZYwwYtZ7UC3SA4GCMGQzZSyEchOYPYVAmT7z5s@public.gmane.org>
2008-01-31 12:56   ` Michael Kerrisk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox