Fork Parent Child Code

Fork Parent Child Code Execution Blocks

fork() will return -1 (to the would-be parent) if the fork doesnt work.
 
if((pid = fork()) < 0){
   //some sort of error occurred
}else{
   if(pid == 0){
     //child goes on from here
   }else{
     //parent goes on from here
   }
}

Source: http://www.cs.brown.edu/courses/cs036/labs/syscall.pdf
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License