Skip to content

Instantly share code, notes, and snippets.

@Cyberax
Created November 19, 2019 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cyberax/c3417c10825c4c025a78f23ea7c4bd9c to your computer and use it in GitHub Desktop.
Save Cyberax/c3417c10825c4c025a78f23ea7c4bd9c to your computer and use it in GitHub Desktop.
Another example
#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