Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <wait.h>
- #include <signal.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/sem.h>
- #include <sys/shm.h>
- #include <limits.h>
- int
- run(char *cmd)
- {
- pid_t pid = fork();
- if (pid < 0) {
- return 0;
- } else if (!pid) {
- execlp(cmd, cmd, NULL);
- _exit(1);
- } else {
- int status;
- wait(&status);
- return (WIFEXITED(status) && !WEXITSTATUS(status));
- }
- }
- int
- main(int argc, char **argv)
- {
- int ok1 = 0, ok2 = 0;
- unsigned long long ok_sum = 0;
- while ((ok1 = run(argv[1])) || (ok2 = run(argv[2]))) {
- ok_sum += ok1 + ok2;
- for (int i = 3; i < argc; ++i) {
- if (!fork()) {
- execlp(argv[i], argv[i], NULL);
- _exit(1);
- }
- }
- int status;
- while (wait(&status) != -1) {
- ok_sum += (WIFEXITED(status) && !WEXITSTATUS(status));
- }
- ok1 = ok2 = 0;
- }
- printf("%llu\n", ok_sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement