When timers are used, there are three options to distinguish how elapsed time is counted or in which time base22 the timer resides. The kernel features the following variants that draw attention to themselves by various signals when a time-out occurs:
□ itimer_real measures the actual elapsed time between activation of the timer and time-out in order to trigger the signal. In this case, the timer continues to tick regardless of whether the system is in kernel mode or user mode or whether the application using the timer is currently running or not. A signal of the sigalrm type is sent when the timer times out.
□ itimer_virtual runs only during the time spent by the owner process of the timer in user mode. In this case, time spent in kernel mode (or when the processor is busy with another application) is ignored. Time-out is indicated by the sigvtalrm signal.
□ itimer_prof calculates the time spent by the process both in user and kernel mode — time continues to elapse when a system call is executed on behalf of the task. Other processes of the system are ignored. The signal sent at time-out is sigprof.
22Often also referred to as time domain.
As already suggested by its name, the primary use of this timer is in the profiling of applications in which a search is made for the most compute-intensive fragments of a program so that these can be optimized accordingly. This is an important consideration, particularly in scientific or operating system-related applications.
The timer type — and the periodic interval length — must be specified when an interval timer is installed. In our example, ttimer_real is used for a real-time timer.
The behavior of alarm timers can be simulated with interval timers by selecting itimer_real as the timer type and deinstalling the timer after the first time-out. Interval timers are therefore a generalized form of alarm timers.
Continue reading here: The alarm and setitimer System Calls
Was this article helpful?