Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <unistd.h>
  4.  
  5. int cnt = 0;
  6.  
  7. void sigint_handler(int signo)
  8. {
  9.     if (cnt < 4) {
  10.         printf("%d\n", cnt);
  11.         fflush(stdout);
  12.         ++cnt;
  13.     } else {
  14.         _exit(0);
  15.     }
  16. }
  17.  
  18. int main()
  19. {
  20.     sigset_t mask, oldmask;
  21.  
  22.     sigemptyset(&mask);
  23.     sigaddset(&mask, SIGINT);
  24.  
  25.     sigprocmask(SIG_BLOCK, &mask, &oldmask);
  26.  
  27.     struct sigaction sa;
  28.  
  29.     sa.sa_handler = sigint_handler;
  30.     sigemptyset(&sa.sa_mask);
  31.     sa.sa_flags = SA_RESTART;
  32.     sigaction(SIGINT, &sa, NULL);
  33.  
  34.     printf("%d\n", getpid());
  35.     fflush(stdout);
  36.     sigprocmask(SIG_UNBLOCK, &mask, &oldmask);
  37.  
  38.     while (1) {
  39.     }
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement