Young India 99

YES-Young Energetic Sincere

Home
Instant Inspiration
Incredible India
Knowledge Transfer(KT)
Placement Puraan
VTU Results
Technical Stuff
Coders Adda
win32 snippets
Windows CE Basics
stock ticker PocketPC
Windows Custom Control
Concatenated SMS
Using Timers in Linux
IPC in Linux
Deadlock Detection Algo
Priority queue spinlocks
Sample Queue C++
Contact Us
 
Using Timers in Linux (sample code) 
 
TIMER_SAMPLE_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 = 5;//waits for 5 seconds before sending timer signal
value.it_value.tv_nsec = 0;

value.it_interval.tv_sec = 5;//sends timer signal every 5 seconds
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);
}


 
Comments
* First name (required):

* Last name (required):
* E-mail address (required):

Phone number:
* Message (required):