Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <signal.h>
- #include <stdio.h>
- #include <string.h>
- #include <sys/time.h>
- void timer_handler (int signum)
- {
- static int count = 0;
- ++count;
- }
- int main ()
- {
- struct sigaction sa;
- struct itimerval timer;
- char c;
- /* Install timer_handler as the signal handler for SIGVTALRM. */
- memset (&sa, 0, sizeof (sa));
- sa.sa_handler = &timer_handler;
- sigaction (SIGALRM, &sa, NULL);
- /* Configure the timer to expire after 250 msec... */
- timer.it_value.tv_sec = 0;
- timer.it_value.tv_usec = 250000;
- /* ... and every 250 msec after that. */
- timer.it_interval.tv_sec = 0;
- timer.it_interval.tv_usec = 1000000 / 100;
- /* Start a virtual timer. It counts down whenever this process is
- executing. */
- setitimer (ITIMER_REAL, &timer, NULL);
- /* Do busy work. */
- while (1) {
- if (fread(&c, sizeof(char), 1, stdin)) printf(".");
- if (feof(stdin)) return EOF;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement