Path: utzoo!attcan!uunet!crdgw1!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: Sleep time interval Message-ID: <14347@smoke.brl.mil> Date: 6 Nov 90 04:23:43 GMT References: <725@macuni.mqcc.mq.oz> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 39 In article <725@macuni.mqcc.mq.oz> martin@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. There is no standard library function that you can count on in all environments for "napping" (the usual name for short sleeps). The following code is adapted from my System V emulation support for 4BSD and exploits the 4BSD select() system call. On System V you might be able to use poll() in a similar way. /* _nap -- support routine for 4.2BSD system call emulations last edit: 29-Oct-1984 D A Gwyn */ extern int _select(); int _nap( usec ) /* returns 0 if ok, else -1 */ long usec; /* delay in microseconds */ { static struct /* `timeval' */ { long tv_sec; /* seconds */ long tv_usec; /* microsecs */ } delay; /* _select() timeout */ delay.tv_sec = usec / 1000000L; delay.tv_usec = usec % 1000000L; return _select( 0, (long *)0, (long *)0, (long *)0, &delay ); }