Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4.  
  5. void sig_handler(int signo)
  6. {
  7. printf("Signal %d", signo);
  8. exit(1);
  9. }
  10.  
  11. int install_sig_handler(void)
  12. {
  13. struct sigaction sa;
  14.  
  15. sa.sa_handler = sig_handler;
  16. sigemptyset(&sa.sa_mask);
  17. sa.sa_flags = 0;
  18.  
  19. if (sigaction(SIGTERM, &sa, NULL) != 0) {
  20. printf("sigaction(SIGTERM) error\n");
  21. return -1;
  22. }
  23.  
  24. if (sigaction(SIGINT, &sa, NULL) != 0) {
  25. printf("sigaction(SIGINT) error\n");
  26. return -1;
  27. }
  28.  
  29. if (sigaction(SIGKILL, &sa, NULL) != 0) {
  30. printf("sigaction(SIGKILL) error\n");
  31. return -1;
  32. }
  33.  
  34. return 0;
  35. }
  36.  
  37. int main(int argc, char const* argv[])
  38. {
  39. install_sig_handler();
  40.  
  41. while(1) {
  42. sleep(60);
  43. }
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement