code_junkie

Using SIGINT

Nov 13th, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include <signal.h>
  2.  
  3. int raise(int sig);
  4.  
  5. kill(getpid(), sig);
  6.  
  7. pthread_kill(pthread_self(), sig);
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <signal.h>
  12.  
  13. void siginthandler(int param)
  14. {
  15. printf("User pressed Ctrl+Cn");
  16. exit(1);
  17. }
  18.  
  19. int main()
  20. {
  21. signal(SIGINT, siginthandler);
  22. while(1);
  23. return 0;
  24. }
  25.  
  26. $ ./a.out
  27. ^CUser pressed Ctrl+C
  28. $
Add Comment
Please, Sign In to add comment