7 fprintf(stderr,"In the main process (pid: %d), about to fork\n",getpid());
14 case -1: perror("fork"); break;
16 fprintf(stderr,"In the forked process (pid: %d), sleeping for 2 sec\n",getpid());
18 fprintf(stderr,"Child done sleeping... exiting\n");
22 fprintf(stderr,"In the main process (child is: %d) waiting for child\n",pid);
23 if(waitpid(pid,&status,0) < 0)
26 fprintf(stderr,"Child process exited (status: %d)\n",status);
31 fprintf(stderr,"1st fork (pid: %d)\n",getpid());
33 fprintf(stderr,"2nd fork (pid: %d).. sleeping\n",getpid());
35 fprintf(stderr,"2nd fork exiting\n");
38 fprintf(stderr,"1st fork (pid: %d) exiting\n",getpid());
42 fprintf(stderr,"1st fork terminated\n");
44 fprintf(stderr,"Sleeping for a bit\n");
47 fprintf(stderr,"Next few pids should be sequential\n");
50 fprintf(stderr,"I am a child %d\n",getpid());
52 fprintf(stderr,"Child %d exiting\n",getpid());
56 for(i=0;i<10;i++) fprintf(stderr,"Waited on %d\n",waitpid(-1,NULL,0));