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