Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (521 Bytes)

1
#include <stdio.h>
2
#include <sys/time.h>
3
#include <signal.h>
4

    
5
volatile int i;
6

    
7
void *tick(int sig)
8
{
9
  printf("tick. i=%d\n", i);
10
  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
  i=0;
33

    
34
  while(1)
35
    i++;
36

    
37
  return 0;
38
}