Skip to content

Instantly share code, notes, and snippets.

@gnosis23
Created June 3, 2014 14:17
Show Gist options
  • Save gnosis23/daae39d62b5fe13a0db4 to your computer and use it in GitHub Desktop.
Save gnosis23/daae39d62b5fe13a0db4 to your computer and use it in GitHub Desktop.
double fork
int main(void){
pid_t = pid;
if((pid = fork()) < 0){
err;
}
else if(pid == 0){
if((pid = fork()) < 0) err;
else if(pid > 0) exit(0);
sleep(2);
printf("second child");
exit(0);
}
if (waitpid(pid, NULL, 0) != pid)
err;
exit(0);
}
@gnosis23
Copy link
Author

gnosis23 commented Jun 3, 2014

prevent zombie process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment