Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/tests/vfork.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 841 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 841 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* |
2 | * usr/klibc/tests/vfork.c |
3 | * |
4 | * vfork is messy on most architectures. Do our best to test it out. |
5 | */ |
6 | |
7 | #include <errno.h> |
8 | #include <stdio.h> |
9 | #include <unistd.h> |
10 | #include <sys/types.h> |
11 | #include <sys/wait.h> |
12 | |
13 | int main(int argc, char *argv[]) |
14 | { |
15 | pid_t f, rv; |
16 | int status; |
17 | |
18 | f = vfork(); |
19 | |
20 | if (f == 0) { |
21 | printf("Child (%d)...\n", (int)getpid()); |
22 | _exit(123); |
23 | } else if (f > 0) { |
24 | int err = 0; |
25 | |
26 | printf("Parent (child = %d)\n", (int)f); |
27 | |
28 | rv = waitpid(f, &status, 0); |
29 | if (rv != f) { |
30 | printf("waitpid returned %d, errno = %d\n", |
31 | (int)rv, errno); |
32 | err++; |
33 | } |
34 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 123) { |
35 | printf("Child process existed with wrong status %d\n", |
36 | status); |
37 | err++; |
38 | } |
39 | return err; |
40 | } else { |
41 | printf("vfork returned %d, errno = %d\n", |
42 | (int)f, errno); |
43 | return 127; |
44 | } |
45 | } |