1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <fcntl.h> #include <unistd.h> #include <sys/wait.h> #include <stdio.h> int main(int argc, char *argv[]) { pid_t f = fork(); if (f < 0) { perror("fork"); return 1; } if (f == 0) { execvp(argv[1], argv + 1); } else { int status = -2; wait(&status); printf("Child: %d\tExit: %d\n", f, status); } }