#include #include #include /* #define DEBUG 1 */ /* #define SLOW 1 */ int main() { pid_t pid; /* fork a child process */ pid = fork(); if( pid < 0 ) { /* error occurred */ fprintf(stderr, "Fork failed!\n"); return 1; } else if( pid == 0 ) { /* child process */ #ifdef SLOW sleep(2); #endif #ifdef DEBUG printf("I am the child! Here I go...\n"); #endif #ifdef SLOW sleep(3); #endif execlp("/bin/ls", "ls", NULL); printf("That was fun! What next?\n"); } else { /* parent process */ #ifdef DEBUG printf("I am the parent! Waiting...\n"); #endif #ifdef SLOW sleep(1); #endif wait(NULL); #ifdef DEBUG printf("Child complete now\n"); #endif } }