Messages in this thread | | | Date | Wed, 14 Jan 2009 11:43:05 +1300 | From | "Michael Kerrisk" <> | Subject | Re: waitid() return value strangeness when infop is NULL |
| |
Test program below. Two test runs, of which the second shows the behavior I'm reporting.
$ ./a.out Created child with PID 7727 infop = 0xbfe608e0 waitid() returned 0 $ ./a.out n Created child with PID 7729 infop = (nil) waitid() returned 7729
===
#define _GNU_SOURCE #include <unistd.h> #include <sys/syscall.h> #include <sys/types.h> #include <sys/wait.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <signal.h> #include <unistd.h>
int main(int argc, char *argv[]) { siginfo_t info, *infop; int options, idtype; long s; pid_t child;
child = fork(); if (child == 0) exit(0); printf("Created child with PID %ld\n", (long) child);
idtype = P_PID; options = WEXITED; infop = (argc > 1 && strchr(argv[1], 'n') != NULL) ? NULL : &info;
printf("infop = %p\n", infop);
s = syscall(SYS_waitid, idtype, child, infop, options, NULL); if (s == -1) { perror("waitid"); exit(EXIT_FAILURE); }
printf("waitid() returned %ld\n", s);
exit(EXIT_SUCCESS); }
| |