1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <sys/types.h> #include <sys/wait.h> #include <unistd.h> int main(int argc, char **argv) { if (argc < 2) return 1; pid_t child = fork(); if (child == -1) { return 1; } else if (child == 0) { execvp(argv[1], argv + 1); return 1; } else { int retval; waitpid(child, &retval, 0); return (retval == 0) ? 0 : 1; } }