A timer is a software facility that allows functions to be invoked at some future moment, after a given time interval has elapsed; a time-out denotes a moment at which the time interval associated with a timer has elapsed.
Timers are widely used both by the kernel and by processes. Most device drivers use timers to detect anomalous conditions — floppy disk drivers, for instance, use timers to switch off the device motor after the floppy has not been accessed for a while, and parallel printer drivers use them to detect erroneous printer conditions.
Timers are also used quite often by programmers to force the execution of specific functions at some future time (see the later section "The setitimer( ) and alarm( ) System Calls").
Implementing a timer is relatively easy. Each timer contains a
field that indicates how far in the future the timer should expire. This
field is initially calculated by adding the right number of ticks to the
current value of
jiffies. The field
does not change. Every time the kernel checks a timer, it compares the
expiration field to the value of
jiffies at the current moment, and the timer
jiffies is greater than
or equal to the stored value.
Linux considers two types of timers called dynamic timers and interval timers . The first type is used by the kernel, while interval timers may be created by processes in User Mode.
One word of caution about Linux timers: since checking for timer functions is always done ...