The following program prints "woke up" only once. I was expecting
it will do so 5 times at the 10, 11, 12, 13, 14 seconds...
#include <stdio.h>
#include <sys/time.h>
#include <signal.h>
#define INTERVAL 10
void wakeup(int signo)
{
printf("woke up\n");
}
typedef struct elem_ {
int index;
struct itimerval timer;
} elem_t;
elem_t arr[5];
main()
{
struct itimerval timer;
struct sigaction sa; /* Signal handler specification structure */
int i;
sa.sa_handler = wakeup;
sa.sa_flags = SA_RESTART;
if (sigaction(SIGALRM, &sa, 0) < 0) {
perror("sigaction");
}
for (i = 0; i < 5; i++) {
memset(&arr.timer, 0, sizeof(struct itimerval));
arr.timer.it_value.tv_usec = 0;
arr.timer.it_value.tv_sec = i + 10;
setitimer(ITIMER_REAL, &arr.timer, NULL);
}
while (1) {
;
}
}
it will do so 5 times at the 10, 11, 12, 13, 14 seconds...
#include <stdio.h>
#include <sys/time.h>
#include <signal.h>
#define INTERVAL 10
void wakeup(int signo)
{
printf("woke up\n");
}
typedef struct elem_ {
int index;
struct itimerval timer;
} elem_t;
elem_t arr[5];
main()
{
struct itimerval timer;
struct sigaction sa; /* Signal handler specification structure */
int i;
sa.sa_handler = wakeup;
sa.sa_flags = SA_RESTART;
if (sigaction(SIGALRM, &sa, 0) < 0) {
perror("sigaction");
}
for (i = 0; i < 5; i++) {
memset(&arr.timer, 0, sizeof(struct itimerval));
arr.timer.it_value.tv_usec = 0;
arr.timer.it_value.tv_sec = i + 10;
setitimer(ITIMER_REAL, &arr.timer, NULL);
}
while (1) {
;
}
}