From: "Phil Endecott" <phil_pgkoc_endecott-wZDNlLIRyE5g9hUCZPvPmw@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: waitpid return value when there are no children
Date: Mon, 14 Jan 2008 17:19:08 +0000 [thread overview]
Message-ID: <1200331148207@dmwebmail.japan.chezphil.org> (raw)
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.
next reply other threads:[~2008-01-14 17:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-14 17:19 Phil Endecott [this message]
[not found] ` <1200331148207-YnoLgZYwwYtZ7UC3SA4GCMGQzZSyEchOYPYVAmT7z5s@public.gmane.org>
2008-01-31 12:56 ` waitpid return value when there are no children Michael Kerrisk
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=1200331148207@dmwebmail.japan.chezphil.org \
--to=phil_pgkoc_endecott-wzdnllirye5g9huczpvpmw@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox