Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/wait.h>
- _Bool
- mysys(const char *str)
- {
- int pid;
- if ((pid = fork()) < 0) {
- return -1;
- } else if (!pid) {
- execlp("/bin/sh", "sh", "-c", str, NULL);
- _exit(0);
- } else {
- int sg;
- waitpid(pid, &sg, 0);
- _Bool fl1 = WIFEXITED(sg);
- _Bool fl2 = fl1 == 0 ? WEXITSTATUS(sg) == 0 : 1;
- return fl1 && fl2;
- }
- }
- int
- main(int argc, char *argv[])
- {
- _Bool fl = mysys(argv[1]);
- if (!fl) {
- fl = mysys(argv[2]);
- }
- if (fl) {
- fl = mysys(argv[3]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment