1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <time.h>
5 
6 // Castor Only
7 #include <sys/wait.h>
8 #include <syscall.h>
9 
10 int
main(int argc,const char * argv[])11 main(int argc, const char *argv[])
12 {
13     const char *program;
14     int pid[10];
15     int status;
16 
17     printf("Spawn parallel test wait any: ");
18     for (int i = 0; i < 10; i++) {
19         program = (i % 2) ? "/bin/false" : "/bin/true";
20 	pid[i] = OSSpawn(program, &argv[0]);
21 	printf("spawn: %lx\n", pid[i]);
22     }
23 
24     for (int i = 0; i < 10; i++) {
25 	wait(&status);
26 	if (!WIFEXITED(status)) {
27 	    printf("wait: process did not exit\n");
28 	    return 0;
29 	}
30 
31 	if (WEXITSTATUS(status) != (i % 2)) {
32 	    printf("wait: unexpected return %lx\n", status);
33 	    return 0;
34 	}
35     }
36 
37     printf("Success!\n");
38 
39     return 0;
40 }
41 
42