Created
November 19, 2019 00:14
-
-
Save Cyberax/c3417c10825c4c025a78f23ea7c4bd9c to your computer and use it in GitHub Desktop.
Another example
This file contains hidden or 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
#include <sys/types.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sys/wait.h> | |
int main() { | |
pid_t pid1; | |
pid_t pid2; | |
int status; | |
if (pid1 = fork()) { | |
/* parent process A */ | |
waitpid(pid1, &status, 0); | |
} else if (!pid1) { | |
setpgid(0,0); | |
setsid(); | |
/* child process B */ | |
if (pid2 = fork()) { | |
exit(0); | |
} else if (!pid2) { | |
/* child process C */ | |
sleep(100); | |
} else { | |
/* error */ | |
} | |
} else { | |
/* error */ | |
abort(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment