| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The sleep() function, which is available on all Unixes, only
allows for a duration specified in seconds. If you want finer
granularity, then you need to look for alternatives:
usleep()
select() or poll(), specifying no file
descriptors to test; a common technique is to write a usleep()
function based on either of these (see the comp.unix.questions FAQ for
some examples)
usleep() using them (see the BSD sources for usleep() for
how to do this)
nanosleep() function
Of the above, select() is probably the most portable (and
strangely, it is often much more efficient than usleep() or an
itimer-based method). However, the behaviour may be different if signals
are caught while asleep; this may or may not be an issue depending on
the application.
Whichever route you choose, it is important to realise that you may be
constrained by the timer resolution of the system (some systems allow
very short time intervals to be specified, others have a resolution of,
say, 10ms and will round all timings to that). Also, as for
sleep(), the delay you specify is only a minimum value;
after the specified period elapses, there will be an indeterminate delay
before your process next gets scheduled.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated on September, 10 2007 using texi2html 1.77.