Subject: waitpid/wait4 discrepancy manpage/implementation ?
To: None <tech-userlevel@netbsd.org>
From: Martin Weber <Ephaeton@gmx.net>
List: tech-userlevel
Date: 11/29/2002 16:28:44
Dunno if this is the right mailinglist, please take any
discussion emerging to the right one if it isn't.
I have stumbled over the following problem which shows a discrepancy
between man waitpid, and what really happens. I include a little
program demonstrating the effect. Either I did not understand the
manpage fully (and then am happy to be taught better), or there is
a problem :) This is observed on
$ uname -a
NetBSD phaeton.entropie.net 1.6K NetBSD 1.6K (PHAETON) #3: Wed Nov 20 10:38:37 CET 2002 root@phaeton.entropie.net:/usr/src/sys/arch/i386/compile/PHAETON i386
Quote from manpage:
(RETURN VALUES)
(...)
If wait4(), wait3() or waitpid() returns due to a stopped or terminated
child process, the process ID of the child is returned to the calling
process. If there are no children not previously awaited, -1 is returned
with errno set to [ECHILD]. Otherwise, if WNOHANG is specified and there
are no stopped or exited children, 0 is returned. If an error is detect-
ed or a caught signal aborts the call, a value of -1 is returned and
errno is set to indicate the error.
"Otherwise (read: "if there are no childrens at all"), if WNOHANG is specified
and there are no stopped or exited children, 0 is returned."
Test program:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
int main (int argc, char *argv[]) {
int x;
if ((waitpid(-1, &x, WNOHANG))==-1) {
perror("waitpid");
exit(EXIT_FAILURE);
}
return (EXIT_SUCCESS);
}
Output:
$ ./tst
waitpid: No child processes
Exit 1
Shouldn't ./tst just return EXIT_SUCCESS as waitpid should return 0 ?
regards,
-martin