SHOW:
|
|
- or go back to the newest paste.
| 1 | #include "sys/prctl.h" | |
| 2 | #include "stdlib.h" | |
| 3 | #include "string.h" | |
| 4 | #include "unistd.h" | |
| 5 | ||
| 6 | /* See http://stackoverflow.com/questions/13221338/how-to-kill-current-command-when-bash-script-is-killed for more info. */ | |
| 7 | ||
| 8 | int main(int argc, char ** argv) | |
| 9 | {
| |
| 10 | pid_t pid = fork(); | |
| 11 | if (pid) | |
| 12 | {
| |
| 13 | waitpid(pid); // Parent waits for child to die. | |
| 14 | } | |
| 15 | else | |
| 16 | {
| |
| 17 | prctl(PR_SET_PDEATHSIG, atoi(argv[1]),0,0,0); // Get a signal if parent dies. | |
| 18 | execvp(argv[2], &(argv[2])); // Execute program (or script). | |
| 19 | } | |
| 20 | } |