Wednesday, 12 July 2017

POSIX timer and clock

The CLOCK_REALTIME clock is a systemwide clock, visible to all processes running on the system and it is defined in time.h header file.

The CLOCK_REALTIME clock measures the amount of time that has elapsed since 00:00:00 January 1, 1970 Greenwich Mean Time (GMT). 

Clock Functions are below

FunctionDescription
clock_getresReturns the resolution of the specified clock
clock_gettimeReturns the current value for the specified clock
clock_settimeSets the specified clock to the specified value


#include 
#include 
 
The timespec data structure consists of two members, tv_sec and tv_nsec, and takes the following form:
typedef struct timespec
  { time_t tv_sec; /* Seconds */
     long tv_nsec; /* Nanoseconds */
 } timespec_t;

struct itimerspec {
       struct timespec it_interval;   /* Timer interval     */
       struct timespec it_value;      /* Initial expiration */
};
 
MemberZeroNon-Zero
it_valueNo expiration value Disarm the timerExpiration value Arm the timer
it_intervalNo reload value Use as a one-shot timerInterval reload value Use as a periodic timer
 
specify a timer that executes only once, 5.25 seconds from now
mytimer.it_value.tv_sec = 5; 
mytimer.it_value.tv_nsec = 250000000; 
mytimer.it_interval.tv_sec = 0; 
mytimer.it_interval.tv_nsec = 0;  
 
timer to execute 15 seconds from now and then at 0.5 second intervals
mytimer.it_value.tv_sec = 15;
mytimer.it_value.tv_nsec = 0; 
mytimer.it_interval.tv_sec = 0; 
mytimer.it_interval.tv_nsec = 500000000;  
 
Timer Functions are below.

FunctionDescription
timer_createReturns a unique timer ID used in subsequent calls to identify a timer based on the systemwide clock
timer_deleteRemoves a previously allocated, specified timer
timer_getoverrunReturns the timer expiration overrun count for the specified timer
timer_gettimeReturns the amount of time before the specified timer is due to expire and the repetition value
timer_settimeSets the value of the specified timer either to an offset from the current clock setting or to an absolute value
 
 

No comments:

Post a Comment