Added basic implementation of destroying a GPT table: just delete the
[AROS.git] / test / clib / waitpid.c
blob120f11a8c0bd9c0f35b0ccaeac83bdf0175b3d8d
1 #include <unistd.h>
2 #include <stdio.h>
3 #include <sys/wait.h>
4 #include <aros/debug.h>
5 #include <errno.h>
6 #include "test.h"
8 #define EXIT_STATUS 123
10 int main()
12 pid_t pid;
13 pid_t wait_pid;
14 int status;
15 char *argv[] = { "Delay", "50", NULL };
16 char *envp[] = { NULL };
18 wait_pid = waitpid(666, NULL, 0);
19 TEST(wait_pid == -1);
20 TEST(errno == ECHILD);
22 pid = vfork();
23 if((int) pid > 0)
25 printf("Created child with pid %d\n", (int) pid);
26 printf("Waiting for child with pid %d to exit.\n", (int) pid);
27 wait_pid = waitpid(pid, &status, 0);
28 TEST((wait_pid == pid));
29 printf("Child %d exited with exit status %d\n", (int) wait_pid, status);
30 TEST((status == EXIT_STATUS));
32 else if(pid == 0)
34 printf("Exiting with status %d\n", EXIT_STATUS);
35 _exit(EXIT_STATUS);
37 else
39 TEST(0);
42 pid = vfork();
43 if((int) pid > 0)
45 printf("Created child with pid %d\n", (int) pid);
46 printf("Waiting for any child to exit.\n");
47 wait_pid = waitpid(-1, &status, 0);
48 TEST((wait_pid == pid));
49 printf("Child %d exited with exit status %d\n", (int) wait_pid, status);
50 TEST((status == EXIT_STATUS));
52 else if(pid == 0)
54 printf("Exiting with status %d\n", EXIT_STATUS);
55 _exit(EXIT_STATUS);
57 else
59 TEST(0);
62 pid = vfork();
63 if((int) pid > 0)
65 printf("Created child with pid %d\n", (int) pid);
66 printf("Waiting for any child to exit without hang.\n");
67 wait_pid = waitpid(-1, &status, WNOHANG);
68 if(wait_pid == 0)
69 wait_pid = waitpid(-1, &status, 0);
70 TEST((wait_pid == pid));
71 printf("Child %d exited with exit status %d\n", (int) wait_pid, status);
72 TEST((status == EXIT_STATUS));
74 else if(pid == 0)
76 printf("Exiting with status %d\n", EXIT_STATUS);
77 _exit(EXIT_STATUS);
79 else
81 TEST(0);
84 pid = vfork();
85 if((int) pid > 0)
87 printf("Created child with pid %d\n", (int) pid);
88 printf("Waiting for any child to exit without hang.\n");
89 wait_pid = waitpid(-1, &status, WNOHANG);
90 TEST((wait_pid == 0));
91 printf("Child didn't exit yet\n");
92 wait_pid = waitpid(-1, &status, 0);
93 TEST((wait_pid == pid));
94 printf("Child %d exited with exit status %d\n", (int) wait_pid, status);
95 TEST((status == 0));
98 else if(pid == 0)
100 execve("C:Delay", argv, envp);
101 _exit(-1);
103 else
105 TEST(0);
108 return 0;
111 void cleanup()