How can I get a finer-grained version of alarm()?

How can I get a finer-grained version of alarm()?


Modern Unixes tend to implement alarms using the setitimer()
function, which has a higher resolution and more options than the simple
alarm() function. One should generally assume that alarm()
and setitimer(ITIMER_REAL) may be the same underlying timer, and
accessing it both ways may cause confusion.



Itimers can be used to implement either one-shot or repeating signals;
also, there are generally 3 separate timers available:




ITIMER_REAL

counts real (wall clock) time, and sends the SIGALRM signal

ITIMER_VIRTUAL

counts process virtual (user CPU) time, and sends the SIGVTALRM
signal

ITIMER_PROF

counts user and system CPU time, and sends the SIGPROF signal;
it is intended for interpreters to use for profiling.



Itimers, however, are not part of many of the standards, despite having
been present since 4.2BSD. The POSIX realtime extensions define some
similar, but different, functions.






Home FAQ