Created
May 23, 2018 19:30
-
-
Save danrl/cdf8b101c89fc64106372f6a842c308e to your computer and use it in GitHub Desktop.
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 <unistd.h> | |
#include <sys/types.h> | |
int main(int argc, char *argv[]) { | |
pid_t pid = fork(); | |
if (pid == 0) { | |
// child 1 migrates to a new session | |
setsid(); | |
pid_t pid2 = fork(); | |
if (pid2 == 0) { | |
// child 2 (daemon) being lazy | |
sleep(30); | |
return 0; | |
} | |
// child 1 exiting ok | |
return 0; | |
} | |
// parent exiting without waiting for the child | |
sleep(5); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment