Creating and using a POSIX (interval) timer

As seen previously, we use the powerful timer_create(2) system call to create a timer for the calling process (or thread, for that matter):

#include <signal.h>#include <time.h>int timer_create(clockid_t clockid, struct sigevent *sevp,                 timer_t *timerid);Link with -lrt.
We have to link with the real time (rt) library to make use of this API. The librt library implements the POSIX.1b Realtime Extensions to POSIX interfaces. Find a link to the librt man page in the Further Reading section on the GitHub repository.

The first parameter passed to timer_create(2) informs the OS of the clock source to be used; we avoid repetition of the matter and refer the reader to the section Obtaining the current time ...

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.