The_Law

Untitled

Nov 20th, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4.  
  5. _Bool
  6. mysys(const char *str)
  7. {
  8.     int pid;
  9.     if ((pid = fork()) < 0) {
  10.         return -1;
  11.     } else if (!pid) {
  12.         execlp("/bin/sh", "sh", "-c", str, NULL);
  13.         _exit(0);
  14.     } else {
  15.         int sg;
  16.         waitpid(pid, &sg, 0);
  17.         _Bool fl1 = WIFEXITED(sg);
  18.         _Bool fl2 = WEXITSTATUS(sg) == 0;
  19.         return fl1 && fl2;
  20.     }
  21. }
  22.  
  23. int
  24. main(int argc, char *argv[])
  25. {
  26.     mysys(argv[1]);
  27.     mysys(argv[2]);
  28.     mysys(argv[3]);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment