LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2007, 07:54 PM   #1
sean04
LQ Newbie
 
Registered: Oct 2007
Posts: 8

Rep: Reputation: 0
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);
}
 
Old 10-07-2007, 11:34 PM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
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;
    timeout.it_value.tv_nsec = 1000;

    timeout.it_interval.tv_sec = timeout.it_value.tv_sec;
    timeout.it_interval.tv_nsec = timeout.it_value.tv_nsec;

    status = timer_create(CLOCK_REALTIME, &evp, &m_nTimerIds[nTimerId]);

    sigaction(evp.sigev_signo, &sig_act, 0);

    if(status < 0)
    {
        fprintf(stderr, "ERROR: Cannot start timer for id: %d.\n", nTimerId);
        return status;
    }

    status = timer_settime(m_nTimerIds[nTimerId], 0, &timeout, NULL);
    if(status < 0)
    {
        perror("settimer failed");
        return -1;
    }
this is relative time based, rather than absolute time based (absolute time being prone to errors such as "The date is really tuesday, but you think its monday").
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux timers arabindav Linux - General 3 05-20-2011 07:33 AM
posix timers mailsteam Programming 7 05-18-2007 11:32 PM
about timers eshwar_ind Programming 1 12-27-2004 09:23 AM
Help with Linux timers samble Programming 8 02-07-2004 10:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration