#include #include #include #include #include int main(void){ int i, n = 4; pid_t childpid; int status; for (i = 1; i < n; ++i) if((childpid = fork()) < 0){ /* fork error */ perror("error in fork"); exit(EXIT_FAILURE); } else if(childpid){ /* parent code */ } else { /* child code - sleep to force some orphans*/ sleep(1); break; } /* mutual code */ printf("This is process %ld with parent %ld\n", (long)getpid(), (long)getppid()); /* Very simple wait with no error checking */ for (i=1; i < n; i++){ wait(&status); } return 0; }