pid = fork();
if (pid == -1) {
perror("Fork failed");
exit(-1);
}
if (pid){
// parent process goes here.
} else {
// child process goes here.
}
pid = fork();
if (pid == -1) {
perror("Fork failed");
exit(-1);
}
if (pid){
waitpid(pid,&status,0);
printf("the child exited, it's pid was %d\n",pid);
// parent process goes here.
} else {
printf("I am the child \n");
sleep(3);
printf("I am the child and I am out of here \n");
// child process goes here.
}