7 fprintf(stderr,"In the main process (pid: %d), about to fork\n",getpid());
13 case -1: perror("fork"); break;
15 fprintf(stderr,"In the forked process (pid: %d), sleeping for 2 sec\n",getpid());
17 fprintf(stderr,"Child done sleeping... exiting\n");
21 fprintf(stderr,"In the main process (child is: %d) waiting for child\n",pid);
22 if(waitpid(pid,&status,0) < 0)
25 fprintf(stderr,"Child process exited (status: %d)\n",status);
30 fprintf(stderr,"1st fork (pid: %d)\n",getpid());
32 fprintf(stderr,"2nd fork (pid: %d).. sleeping\n",getpid());
34 fprintf(stderr,"2nd fork exiting\n");
40 fprintf(stderr,"1st fork terminated\n");
42 fprintf(stderr,"Sleeping for a bit\n");
44 fprintf(stderr,"Next few pids should be sequential\n");
47 fprintf(stderr,"I am a child %d\n",getpid());
52 for(i=0;i<10;i++) fprintf(stderr,"Waited on %d\n",waitpid(-1,NULL,0));