Advertisement
1fractal

Untitled

Nov 13th, 2020 (edited)
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 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. volatile sig_atomic_t compteur;
  12.  
  13. void handlerSIGINT(int sig) {
  14.    compteur++;
  15.    printf("Compteur = %d\n",compteur);
  16. }
  17.  
  18. int main() {
  19.     compteur = 0;
  20.     struct sigaction s;
  21.     sigset_t masque;
  22.  
  23.     //Init
  24.     sigemptyset(&s.sa_mask);
  25.     s.sa_handler    = handlerSIGINT;
  26.     s.sa_flags      = 0;
  27. //    sigaddset(&s.sa_mask, SIGQUIT);
  28.     //Redirige le signal
  29.     sigaction(SIGINT, &s, NULL);
  30.     //attend 5 interuptions
  31.     sigemptyset(&masque);
  32.     while (compteur < 5)
  33.         sigsuspend(&masque);
  34.  
  35.     return EXIT_SUCCESS;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement