From: Michael Kerrisk <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
To: Phil Endecott
<phil_vonar_endecott-wZDNlLIRyE5g9hUCZPvPmw@public.gmane.org>
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: waitpid return value when there are no children
Date: Thu, 31 Jan 2008 13:56:37 +0100 [thread overview]
Message-ID: <47A1C585.3070402@gmail.com> (raw)
In-Reply-To: <1200331148207-YnoLgZYwwYtZ7UC3SA4GCMGQzZSyEchOYPYVAmT7z5s@public.gmane.org>
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
prev parent reply other threads:[~2008-01-31 12:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47A1C585.3070402@gmail.com \
--to=mtk.manpages-gm/ye1e23mwn+bqq9rbeug@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=phil_vonar_endecott-wZDNlLIRyE5g9hUCZPvPmw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.