Advertisement
Guest User

Untitled

a guest
May 25th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. // Task 4
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <signal.h>
  5.  
  6. volatile time_t sigtime = 0;
  7. int count = 0;
  8.  
  9. void handler(int sig) {
  10.     printf("SIGINT: Count=%d\n", ++count);
  11.     time(&sigtime);
  12. }
  13.  
  14. int main(int argc, const char *argv[]) {
  15.     time_t last = 0;
  16.  
  17.     signal(SIGINT, handler);
  18.  
  19.     printf("Start\n");
  20.     sigtime = time(NULL);
  21.     while(time(NULL) - sigtime < 2)
  22.         sleep(1);
  23.     printf("Done\n");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement