The following program demonstrates the API POSIX timers, which consists of the three system calls:
The program simulates running tasks. The program creates two tasks, t1 and t2, and sents a timer to run t1 every four seconds, and t2 every eight seconds. The timer sends the process the realtime signal (RTMINSIG + 4), which on most systems is the value 38. The data that the program attaches to the realtime system is a pointer to the task; thus, when the timer goes off, the program can immediately retrieve the corresponding task. Finally, rather than establish a signal handler for the timer, the program synchronously waits on the signal using sisuspend. Here, sigsuspend also waits for SIGINT, for which it exits the process.