Project

General

Profile

Statistics
| Revision:

root / branches / simulator / projects / simulator / test / test_timer.c @ 1042

History | View | Annotate | Download (521 Bytes)

1 961 bneuman
#include <stdio.h>
2
#include <sys/time.h>
3
#include <signal.h>
4
5 986 bneuman
volatile int i;
6
7 961 bneuman
void *tick(int sig)
8
{
9 986 bneuman
  printf("tick. i=%d\n", i);
10 961 bneuman
  fflush(stdout);
11
12
  return NULL;
13
}
14
15
int main()
16
{
17
  int ret;
18
  struct itimerval iv;
19
20
  iv.it_interval.tv_sec = 1;
21
  iv.it_interval.tv_usec = 0;
22
  iv.it_value.tv_sec = 5;
23
  iv.it_value.tv_usec = 0;
24
25
  signal(SIGVTALRM, tick);
26
27
  ret = setitimer(ITIMER_VIRTUAL, &iv, NULL);
28
29
  printf("setitimer returned %d.\n waiting...\n", ret);
30
  fflush(stdout);
31
32 986 bneuman
  i=0;
33 961 bneuman
34 986 bneuman
  while(1)
35
    i++;
36
37 961 bneuman
  return 0;
38
}