Advertisement
1fractal

Untitled

Nov 13th, 2020
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <dirent.h>
  3. #include <file.h>
  4. #include <string.h>
  5. #include <sys/stat.h>
  6. #include <stdbool.h>
  7. #include <wait.h>
  8.  
  9. #define SIGLIMIT 5
  10.  
  11. int flag = true;
  12.  
  13. void handlerSIGINT(int sig) {
  14.     static int counter = 0;
  15.     if (counter > SIGLIMIT) {
  16.         printf("SIG counter %d", counter);
  17.         flag = false;
  18.     }
  19.  
  20. }
  21.  
  22. int main() {
  23.  
  24.     struct sigaction s;
  25.  
  26.     s.sa_handler = handlerSIGINT;
  27.     s.sa_flags = 0;
  28.     sigemptyset(&s.sa_mask);
  29.     sigaddset(&s.sa_mask, SIGQUIT);
  30.     sigaddset(&s.sa_mask, SIGINT);
  31.  
  32.     sigaction(SIGINT, &s, NULL);
  33.  
  34.     for (int i = 0; flag; ++i) {
  35.         sigsuspend(&s.sa_mask);
  36.     }
  37.  
  38.     return EXIT_SUCCESS;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement