main() { char *prog = NULL; char **args = NULL; // Read the input a line at a time, and parse each line into the program // name and its arguments. End loop if we've reached the end of the input. while (readAndParseCmdLine(&prog, &args)) { // Create a child process to run the command. int child_pid = fork(); if (child_pid == 0) { // I'm the child process. // Run program with the parent's input and output. exec(prog, args); // NOT REACHED } else { // I'm the parent; wait for the child to complete. wait(child_pid); return 0; } } }