Posix timers not behaving correctly
Hi I don't understand how this isn't working correctly...I'm running Linux Kernel 2.6.9. What's happening is that as soon as I call the timer_settime function it immediately triggers the signal handler. No matter how big I set the time. Here's the code:
sigs.sa_handler = signal_handler_function; sigemptyset(&sigs.sa_mask); if (sigaction(SIGALRM, &sigs, (struct sigaction *) NULL) != 0) { exit(1); } if (timer_create(CLOCK_REALTIME, (struct sigevent *) NULL, &timer_id ) != 0) { exit(1); } ItimerSpec.it_value.tv_sec = sec; //assume correct values ItimerSpec.it_value.tv_nsec = nsec;//assume correct values ItimerSpec.it_interval.tv_sec = 0; ItimerSpec.it_interval.tv_nsec = 0; if (timer_settime(timer_id,TIMER_ABSTIME,&ItimerSpec, NULL) != 0) { exit(1); } |
you might want to read the manpages.
The TIMER_ABSTIME flag is probably not what you want, unless you're getting seconds and nanoseconds in absolute time. In the above function, there's no indication that values you're getting _are_ correct, and the symptom you're seeing is characteristic of incorrect values. I've got some timer code that works, and it looks like: Code:
timeout.it_value.tv_sec = 0; |
All times are GMT -5. The time now is 03:21 PM. |