Update.
[glibc.git] / posix / test-vfork.c
blob2abeb5ae14593790576b4069f5b860d0301a49ed
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <error.h>
4 #include <errno.h>
5 #include <sys/wait.h>
7 void noop (void);
9 #define NR 2 /* Exit code of the child. */
11 int
12 main (void)
14 pid_t pid;
15 int status;
17 printf ("Before vfork\n");
18 fflush (stdout);
19 pid = vfork ();
20 if (pid == 0)
22 /* This will clobber the return pc from vfork in the parent on
23 machines where it is stored on the stack, if vfork wasn't
24 implemented correctly, */
25 noop ();
26 _exit (NR);
28 else if (pid < 0)
29 error (1, errno, "vfork");
30 printf ("After vfork (parent)\n");
31 if (waitpid (0, &status, 0) != pid
32 || !WIFEXITED (status) || WEXITSTATUS (status) != NR)
33 exit (1);
34 exit (0);
37 void
38 noop ()