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     int origpid[10], pid[10];
14     const char *program;
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 	origpid[i] = OSSpawn(program, &argv[0]);
21 	printf("spawn: %lx\n", pid[i]);
22     }
23 
24     for (int i = 0; i < 10; i ++) {
25 	pid[i] = wait(&status);
26 	if (!WIFEXITED(status)) {
27 	    printf("wait: process did not exit\n");
28 	    return 0;
29 	}
30 
31 	if (pid[i] != origpid[i]) {
32 	    printf("wait: expected pid %d found %d\n", origpid, pid);
33 	    return 0;
34 	}
35 
36 	if (WEXITSTATUS(status) != (i % 2)) {
37 	    printf("wait: unexpected return %lx\n", status);
38 	    return 0;
39 	}
40     }
41 
42     printf("Success!\n");
43 
44     return 0;
45 }
46