Copyright clean-up (part 1):
[AROS.git] / test / clib / vfork_execl.c
blobf495ea2dc77c9dead2c24949182830111d9bb912
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;
16 /* Test vfork and a child doing execl() */
17 pid = vfork();
18 if((int) pid > 0)
20 printf("I'm parent, I have a child with pid %d\n", (int) pid);
21 waitpid(pid, NULL, 0);
23 else if(pid == 0)
25 execl("C:Echo", "Echo", "I'm child", NULL);
26 _exit(1);
28 else
30 TEST(0);
32 printf("\n");
34 /* Testing child trying to exec non-existing program */
35 pid = vfork();
36 if((int) pid > 0)
38 printf("I'm parent, I have a child with pid %d\n", (int) pid);
39 waitpid(pid, NULL, 0);
41 else if(pid == 0)
43 TEST(execl(":XYZ/NotExist", "NotExist", "I'm child", NULL) == -1);
44 _exit(0);
46 else
48 TEST(0);
51 /* Testing nested vfork() + execl() */
52 pid = vfork();
53 if((int) pid > 0)
55 printf("I'm parent, I have a first child with pid %d\n", (int) pid);
56 pid_t pid2 = vfork();
57 if((int) pid2 > 0)
59 printf("I'm parent, I have a second child with pid %d\n", (int) pid2);
60 waitpid(pid2, NULL, 0);
62 else if(pid2 == 0)
64 execl("C:Echo", "Echo", "I'm the second child of a parent", NULL);
65 _exit(1);
67 waitpid(pid, NULL, 0);
69 else if(pid == 0)
71 //printf("I'm child of a parent\n");
72 pid_t pid2 = vfork();
73 if((int) pid2 > 0)
75 //printf("I'm child, I have my child with pid %d\n", (int) pid2);
76 waitpid(pid2, NULL, 0);
78 else if(pid2 == 0)
80 execl("C:Echo", "Echo", "I'm child of a child", NULL);
81 _exit(1);
83 _exit(0);
85 else
87 TEST(0);
90 return OK;
93 void cleanup()