#include #include #include #include #include #include #include #include #include #include void fils(void) { int n; srand(getpid()); exit(rand() % 128); } int main(int argc, char *argv[]) { int n, max, status; assert(argc == 2); n = strtol(argv[1], NULL, 0); for (int i = 0; i <= n; i++) { pid_t p = fork(); assert(p != -1); if (p == 0) { fils(); } } wait(&status); if (WIFEXITED(status)) max = WEXITSTATUS(status); for (int i = 0; i <= n; i++) { wait(&status); if (WIFEXITED(status)) { if (WEXITSTATUS(status) > max) max = WEXITSTATUS(status); } } printf("Le maximum est %d\n", max); exit(0); }