Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <sys/time.h>
  5.  
  6. void timer_handler (int signum)
  7. {
  8. static int count = 0;
  9. ++count;
  10. }
  11.  
  12. int main ()
  13. {
  14. struct sigaction sa;
  15. struct itimerval timer;
  16. char c;
  17.  
  18. /* Install timer_handler as the signal handler for SIGVTALRM. */
  19. memset (&sa, 0, sizeof (sa));
  20. sa.sa_handler = &timer_handler;
  21. sigaction (SIGALRM, &sa, NULL);
  22.  
  23. /* Configure the timer to expire after 250 msec... */
  24. timer.it_value.tv_sec = 0;
  25. timer.it_value.tv_usec = 250000;
  26. /* ... and every 250 msec after that. */
  27. timer.it_interval.tv_sec = 0;
  28. timer.it_interval.tv_usec = 1000000 / 100;
  29. /* Start a virtual timer. It counts down whenever this process is
  30. executing. */
  31. setitimer (ITIMER_REAL, &timer, NULL);
  32.  
  33. /* Do busy work. */
  34. while (1) {
  35. if (fread(&c, sizeof(char), 1, stdin)) printf(".");
  36. if (feof(stdin)) return EOF;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement