Register nameservers dynamically instead of writing them to disk. It is
[AROS.git] / test / clib / vfork.c
blob4f66e9eb651bea77cef5ed5e14b20158aa336ed4
1 #include <unistd.h>
2 #include <stdio.h>
3 #include <aros/debug.h>
4 #include <sys/wait.h>
5 #include "test.h"
7 int main()
9 pid_t pid;
10 int retval = RETURN_OK;
12 pid = vfork();
13 if((int) pid > 0)
15 int status = -1;
16 printf("I'm parent, I have a child with pid %d\n", (int) pid);
17 waitpid(pid, &status, 0);
18 if (status != 1)
19 return RETURN_FAIL;
21 else if(pid == 0)
23 // Only _exit() and exec*() are valid in child context
24 _exit(1);
26 else
28 TEST(0);
31 pid = vfork();
32 if((int) pid > 0)
34 printf("I'm parent, I have a first child with pid %d\n", (int) pid);
35 pid_t pid2 = vfork();
36 if((int) pid2 > 0)
38 int status = -1;
39 printf("I'm parent, I have a second child with pid %d\n", (int) pid2);
40 waitpid(pid2, &status, 0);
41 if (status != 2)
42 return RETURN_FAIL;
44 else if(pid2 == 0)
46 // Only _exit(), vfork(), and exec*() are valid in child context
47 _exit(2);
49 waitpid(pid, NULL, 0);
51 else if(pid == 0)
53 pid_t pid2 = vfork();
54 int retval = 3;
55 if((int) pid2 > 0)
57 // I'm child, I have my child with pid2
58 int status = -1;
59 waitpid(pid2, &status, 0);
60 if (status != 4)
61 retval = RETURN_FAIL;
63 else if(pid2 == 0)
65 // I am the child of a child
66 _exit(4);
68 _exit(retval);
70 else
72 TEST(0);
75 return retval;
78 void cleanup()