#include #include #include #include int main() { pid_t pid; switch( pid = fork() ) { case -1: printf("fork failed"); break; case 0: //first child printf("\nI am the first child, my pid is %d", getpid()); fflush(stdout); sleep( 60 ) ; break; default: //parent //sleep(5); /** sleep is generating problems **/ printf("\nI am the parent process, my pid is %d", getpid()); printf("\ngenerating a new child"); fflush(stdout); switch(pid = fork()) { case -1: printf("fork failed"); break; case 0: //second child printf("\nI am, the second child, my pid is %d", getpid()); fflush( stdout ) ; sleep( 60 ) ; break; default: //parent wait((int *)0); printf("\nback to parent, my pid is %d \n", getpid()); printf( "Parent exiting\n" ) ; } } return 0; }