2023-09-02 22:42:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
// Castor Only
|
2023-10-03 04:28:38 +00:00
|
|
|
#include <sys/wait.h>
|
2023-09-02 22:42:00 +00:00
|
|
|
#include <syscall.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, const char *argv[])
|
|
|
|
{
|
2023-10-03 04:28:38 +00:00
|
|
|
char *program;
|
|
|
|
int pid[10];
|
|
|
|
int status;
|
2023-09-02 22:42:00 +00:00
|
|
|
|
2023-09-03 18:55:51 +00:00
|
|
|
printf("Spawn parallel test wait any: ");
|
2023-09-02 22:42:00 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2023-10-03 04:28:38 +00:00
|
|
|
program = (i % 2) ? "/bin/false" : "/bin/true";
|
|
|
|
pid[i] = OSSpawn(program, &argv[0]);
|
|
|
|
printf("spawn: %lx\n", pid[i]);
|
2023-09-02 22:42:00 +00:00
|
|
|
}
|
2023-10-03 04:28:38 +00:00
|
|
|
|
2023-09-02 22:42:00 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2023-10-03 04:28:38 +00:00
|
|
|
wait(&status);
|
|
|
|
if (!WIFEXITED(status)) {
|
|
|
|
printf("wait: process did not exit\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WEXITSTATUS(status) != (i % 2)) {
|
|
|
|
printf("wait: unexpected return %lx\n", status);
|
|
|
|
return 0;
|
|
|
|
}
|
2023-09-02 22:42:00 +00:00
|
|
|
}
|
2023-10-03 04:28:38 +00:00
|
|
|
|
2023-09-02 22:42:00 +00:00
|
|
|
printf("Success!\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|