Guest User

Wrapper to Nicely Kill a Process on a SIGKILL

a guest
Nov 6th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include "sys/prctl.h"
  2. #include "stdlib.h"
  3. #include "string.h"
  4. #include "unistd.h"
  5.  
  6. int main(int argc, char ** argv)
  7. {
  8.     pid_t pid = fork();
  9.     if (pid)
  10.     {
  11.         waitpid(pid); // Parent waits for child to die.
  12.     }
  13.     else
  14.     {
  15.         prctl(PR_SET_PDEATHSIG, atoi(argv[1]),0,0,0); // Get a signal if parent dies.
  16.         execvp(argv[2], &(argv[2])); // Execute program (or script).
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment