Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/wait.h>
- void
- execute(char *arg)
- {
- pid_t pid = fork();
- if (pid == -1) {
- _exit(1);
- } else if (!pid) {
- execlp(arg, arg, NULL);
- _exit(1);
- }
- return;
- }
- int
- check_status(int status)
- {
- if ((WIFEXITED(status) && !WEXITSTATUS(status)) == 1) {
- return 0;
- } else {
- return 1;
- }
- }
- int
- main(int argc, char *argv[])
- {
- int status;
- execute(argv[1]);
- wait(&status);
- if (!check_status(status)) {
- execute(argv[3]);
- wait(&status);
- return check_status(status);
- } else {
- execute(argv[2]);
- wait(&status);
- if (!check_status(status)) {
- execute(argv[3]);
- wait(&status);
- return check_status(status);
- }
- }
- return 1;
- }
Advertisement
RAW Paste Data
Copied
Advertisement