gby / hacks

Various hacks with no other place

This URL has Read+Write access

hacks / timer_test.c
100644 48 lines (34 sloc) 0.714 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <signal.h>
 
 
struct itimerspec tick = { {0, 10 * 1000}, {0, 10 * 1000} } ;
 
void sigusr(int signal) {
 
return;
}
 
int main (void) {
 
 
timer_t timerid;
struct timespec ts;
struct sigevent sigev = {
.sigev_notify = SIGEV_SIGNAL,
.sigev_signo = SIGUSR1
};
 
signal(SIGUSR1, sigusr);
 
if (timer_create(CLOCK_MONOTONIC, &sigev, &timerid) == -1) {
perror("timer_create");
exit(1);
}
 
if (timer_settime(timerid, 0, &tick, NULL )== -1) {
perror("timer_create");
exit(1);
}
 
while(1) {
pause();
}
 
if (timer_delete(timerid) == -1) {
perror("timer_delete");
exit(1);
}
 
return 0;
}