Sleep time interval

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Wed Nov 7 06:34:01 AEST 1990


In article <14347 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
: In article <725 at macuni.mqcc.mq.oz> martin at macadam.mqcs.mq.oz.au (Martin Foord) writes:
: >Is the smallest interval of sleep time the integer 1? Is there anyway of
: >sleeping from a C program for a smaller period of time ?
: 
: The first thing you need to be aware of is that all you can specify is a
: MINIMUM amount of delay; the actual delay will depend on scheduling
: issues such as system load, and could be arbitrarily large if you're
: unlucky.

The second thing you need to be aware of is that it doesn't necessarily
specify the MINIMUM delay either.  If you say sleep(1), some implementations
will sleep till the top of the next second, which could be a very small
fraction of a second away.  So sleep(n) sleeps a minimum of n-1 seconds
on such machines.  In terms of portability, sleep(1) is virtually
worthless (except in a statistical sense) without knowing when in the
second it's going to sleep.

Machines on which alarm() is implemented using setitimer() do not appear
to have this problem.  It's possible it's been fixed elsewhere too--some
of my databanks haven't been updated in quite some time.  I could even
be getting confused with other OS's.  Caveat Programmor.

Larry Wall
lwall at jpl-devvax.jpl.nasa.gov



More information about the Comp.unix.questions mailing list