mesa: simplify dependencies in mmakefiles
[AROS.git] / test / clib / vfork.c
blob445c60e145b67ffc803a81d9392e8305918f78eb
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <aros/debug.h>
9 #include <sys/wait.h>
10 #include "test.h"
12 int main()
14 pid_t pid;
15 int retval = RETURN_OK;
17 pid = vfork();
18 if((int) pid > 0)
20 int status = -1;
21 printf("I'm parent, I have a child with pid %d\n", (int) pid);
22 waitpid(pid, &status, 0);
23 if (status != 1)
24 return RETURN_FAIL;
26 else if(pid == 0)
28 printf("I'm child\n");
29 _exit(1);
31 else
33 TEST(0);
36 pid = vfork();
37 if((int) pid > 0)
39 printf("I'm parent, I have a first child with pid %d\n", (int) pid);
40 pid_t pid2 = vfork();
41 if((int) pid2 > 0)
43 int status = -1;
44 printf("I'm parent, I have a second child with pid %d\n", (int) pid2);
45 waitpid(pid2, &status, 0);
46 if (status != 2)
47 return RETURN_FAIL;
49 else if(pid2 == 0)
51 printf("I'm second child\n");
52 _exit(2);
54 waitpid(pid, NULL, 0);
56 else if(pid == 0)
58 pid_t pid2 = vfork();
59 int retval = 3;
60 if((int) pid2 > 0)
62 printf("I'm child, I have my child with pid2 %d\n", (int) pid2);
63 int status = -1;
64 waitpid(pid2, &status, 0);
65 if (status != 4)
66 retval = RETURN_FAIL;
68 else if(pid2 == 0)
70 printf("I'm the child of a child\n");
71 _exit(4);
73 _exit(retval);
75 else
77 TEST(0);
80 return retval;
83 void cleanup()