#include // required for fork() #include // required for wait() #include // required for perror() #include // required for exit() int main(int argc, char *argv[]) // standard main() function { int status = EXIT_SUCCESS; // child process exit status pid_t pid = fork(); // fork child process switch (pid) // check fork() return value { case -1: // an error occurred perror("fork"); // print an error message status = EXIT_FAILURE; // exit with failure status break; case 0: // this is the child process printf("child\n"); // execute child code break; default: // parent, pid = child ID printf("parent\n"); // execute parent code wait(&status); // wait for child to exit } return status; // return the child status }