Querying the timer

A given POSIX timer can be queried at any point to fetch the time remaining to timer expiry via the timer_gettime(2) system call API; its signature is as follows:

#include <time.h>int timer_gettime(timer_t timerid, struct itimerspec *curr_value);

Quite obviously, the first parameter passed to timer_gettime(2) is the ID of the particular timer to query, and the second parameter passed is the value result-style return—the time to expiry is returned in it (within the structure of type itimerspec).

As we know from preceding, the struct itimerval itself consists of two data structures of type timespec; the time remaining to timer expiry will be placed in the curr_value->it_value member. If this value is 0, it implies that the ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.