I’m trying to use a POSIX timer, but my code can’t run.
timer_t id_timer_;
// some code. timer_create(), etc.
void timerPeriod (unsigned long sec, unsigned long nsec)
{
struct itimerspec myperiod;
myperiod.it_interval.tv_sec = sec;
myperiod.it_interval.tv_nsec = nsec;
myperiod.it_value.tv_sec = sec;
myperiod.it_value.tv_nsec = nsec;
if (timer_settime (&id_timer_, 0, &myperiod, 0))
perror("timer_settime");
}
It returns timer_settime: Invalid argument, while arguments are looking good to me.
I also tried timer_settime(id_timer_, 0, &myperiod, 0) (without the & before id_timer_), which I think is the good way to use timer_settime() : segmentation fault…
Any clue ?
In ordre to create the timer, the
struct sigactionmust be properly set.In my previous code,
sa_flagswas set to0instead ofSA_SIGINFO.More info on kernel.org