Created
June 3, 2014 14:17
-
-
Save gnosis23/daae39d62b5fe13a0db4 to your computer and use it in GitHub Desktop.
double fork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
prevent zombie process