Advertisement
wowonline

Untitled

Dec 12th, 2021
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <sys/wait.h>
  5.  
  6. int
  7. execute(char *arg)
  8. {
  9.     int status = 0;
  10.     pid_t pid = fork();
  11.     if (pid == -1) {
  12.         return 0;
  13.     } else if (!pid) {
  14.         execlp(arg, arg, NULL);
  15.         _exit(1);
  16.     }
  17.    
  18.     wait(&status);
  19.  
  20.     return (WIFEXITED(status) && !WEXITSTATUS(status));
  21. }
  22.  
  23. int
  24. main(int argc, char *argv[])
  25. {
  26.     return ((!execute(argv[1]) || !execute(argv[2])) && !execute(argv[3]));
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement