]>
Commit | Line | Data |
---|---|---|
d0ab7780 UD |
1 | #include <stdio.h> |
2 | #include <unistd.h> | |
3 | #include <error.h> | |
4 | #include <errno.h> | |
464d646f | 5 | #include <sys/wait.h> |
d0ab7780 UD |
6 | |
7 | void noop (void); | |
8 | ||
d48f4d53 UD |
9 | #define NR 2 /* Exit code of the child. */ |
10 | ||
d0ab7780 UD |
11 | int |
12 | main (void) | |
13 | { | |
d48f4d53 UD |
14 | pid_t pid; |
15 | int status; | |
d0ab7780 UD |
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 (); | |
d48f4d53 | 26 | _exit (NR); |
d0ab7780 UD |
27 | } |
28 | else if (pid < 0) | |
29 | error (1, errno, "vfork"); | |
30 | printf ("After vfork (parent)\n"); | |
d48f4d53 | 31 | if (waitpid (0, &status, 0) != pid |
b1195070 | 32 | || !WIFEXITED (status) || WEXITSTATUS (status) != NR) |
d48f4d53 | 33 | exit (1); |
d0ab7780 UD |
34 | exit (0); |
35 | } | |
36 | ||
37 | void | |
38 | noop () | |
39 | { | |
40 | } |