Skip to content

Instantly share code, notes, and snippets.

@dqminh
Created November 20, 2014 19:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dqminh/e8a7a2a98b72ac8226e8 to your computer and use it in GitHub Desktop.
#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