Created
November 20, 2014 19:08
-
-
Save dqminh/e8a7a2a98b72ac8226e8 to your computer and use it in GitHub Desktop.
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
#include <errno.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <signal.h> | |
#include <sys/prctl.h> | |
pid_t pid1; | |
void mhandler(int signum) { | |
fprintf(stderr, "parent got signal %d\n", signum); | |
if (pid1 > 0) { | |
kill(pid1, signum); | |
} | |
} | |
int main(int argc, char *argv[]) { | |
pid1 = fork(); | |
if (pid1 == 0) { | |
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); | |
execv("something", argv); | |
} else { | |
signal(SIGINT, mhandler); | |
signal(SIGHUP, mhandler); | |
signal(SIGTERM, mhandler); | |
int status = 0; | |
if (waitpid(pid1, &status, NULL) == -1) { | |
exit(1); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment