#include <iostream>
#include <string.h>
#include <cstdlib>
#include <unistd.h>
#include <signal.h>

bool terminer = false; // drapeau de terminaison
int cpt = 0; // compte les signaux SIGINT reçus

void gest(int s) { // gestionnaire de signal
  cpt++;
  std::cout << "SIGINT reçu (cpt = " << cpt << ")" << std::endl;
  if(cpt == 5) terminer = true;
}

int main(int argc, char *arv[]) {
  // installation du gestionnaire pour SIGINT
  struct sigaction s;
  sigaction(SIGINT, NULL, &s);
  s.sa_handler = gest;
  sigaction(SIGINT, &s, NULL);
  
  while(1) {
    std::cout << "RRRRR..." << std::endl;
    sleep(1);
    if(terminer) break;
  }
  std::cout << "Je me termine..." << std::endl;
  return 0;
}
