Fedora Linux Support Community & Resources Center
  #1  
Old 8th January 2012, 01:21 PM
newbie14 Offline
Registered User
 
Join Date: Feb 2010
Posts: 104
windows_xp_2003ie
C calling a function at exact every second?

I need to call a function every second exactly as I want to store the data based on the every second so I cannot miss the second? What is best method in C?

Below is a skeleton of the timer_create method is this reliable enough?

Code:
#include <stdio.h>
#include <time.h>
#include <signal.h>

timer_t gTimerid;

void start_timer(void)
{


struct itimerspec value;

value.it_value.tv_sec = 1;
value.it_value.tv_nsec = 0;

value.it_interval.tv_sec = 1;
value.it_interval.tv_nsec = 0;

timer_create (CLOCK_REALTIME, NULL, &gTimerid);

timer_settime (gTimerid, 0, &value, NULL);

}

void stop_timer(void)
{


struct itimerspec value;

value.it_value.tv_sec = 0;
value.it_value.tv_nsec = 0;

value.it_interval.tv_sec = 0;
value.it_interval.tv_nsec = 0;

timer_settime (gTimerid, 0, &value, NULL);


}


void timer_callback(int sig) {

 printf(" Catched timer signal: %d ... !!\n", sig);

}

int main(int ac, char **av)
{
    (void) signal(SIGALRM, timer_callback);
    start_timer();
    while(1);
}
Reply With Quote
Reply

Tags
calling, exact, function

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to download an .rpm with exact file name ? darkman088 Using Fedora 4 13th November 2010 02:23 AM
D2D recovery / EXACT HDD copy pepe123 Installation and Live Media 12 13th July 2007 12:10 PM
Exact Cause for FC6 Frequent Crash dmode EOL (End Of Life) Versions 3 27th April 2007 08:39 AM
RAW/EXACT CD/DVD copy steve941 Using Fedora 1 9th August 2005 11:58 PM


Current GMT-time: 18:51 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat