Update.
[platform/upstream/glibc.git] / posix / test-vfork.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <error.h>
4 #include <errno.h>
5 #include <sys/wait.h>
6
7 void noop (void);
8
9 #define NR      2       /* Exit code of the child.  */
10
11 int
12 main (void)
13 {
14   pid_t pid;
15   int status;
16
17   printf ("Before vfork\n");
18   fflush (stdout);
19   pid = vfork ();
20   if (pid == 0)
21     {
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);
27     }
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 (NR))
33     exit (1);
34   exit (0);
35 }
36
37 void
38 noop ()
39 {
40 }