/** * To run the program: * ./a.out program arg1 arg2 arg3 ... * Two IMPORTANT things: * First: How to use portion of the argv * Second: The first element of the argv in the execvp invocation * needs to be the name of the child process */ #include #include #include #include int main(int argc, char *argv[]) { char *program = argv[1]; /* the argv[] which will be given to the child process must have the "child program name" as the argv[0], so argv only need to increase by 1 */ argv++; int pid; if ((pid = fork()) == -1) { printf("fork failed!\n"); exit(1); } else if (pid == 0) { /* child */ execvp(program, argv); } else { /* parent */ wait(0); } return 0; }