Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!amdcad!sun!exodus!newstop!male!mutchler From: mutchler@zule.EBay.Sun (Dan Mutchler) Newsgroups: comp.unix.internals Subject: Re: Can Unix sleep in terms of mili/micro? Message-ID: Date: 11 Sep 90 21:05:10 GMT References: <24437@adm.BRL.MIL> <84@dlss2.UUCP> Sender: news@male.EBay.Sun.COM Distribution: usa Lines: 45 In-reply-to: james@dlss2.UUCP's message of 11 Sep 90 12:11:17 GMT In article <84@dlss2.UUCP> james@dlss2.UUCP (James Cummings) writes: In article <24437@adm.BRL.MIL> TAYBENGH%NUSDISCS.BITNET@cunyvm.cuny.edu writes: > > Can Unix sleep in terms of mili or mirco second? I am aware that >sleep() can only sleep in terms of second. Please specify the Unix Dialect >when u reply. Thanks. How 'bout: main() { sleep_less_than_sec(25); exit(0); } sleep_less_than_sec(x) int x; { int i; for (i = 0;i <= x;i++) ; } I'd think that would give you approx. 25 clock cycles, dependent on the machine, the load on the machine, etc. Unless a context switch occurs, which is quite possible. That may still be okay if times much greater than 25 clock cycles are okay. That is you need a sleep that sleeps at least x milliseconds. Looping is in general a bad delay because different machines require different CPU time to perform the loop. Intelligent use of macros can help this, but unless it is in the kernel where a context switch cannot occur you can only guareentee that you will not return before the required delay. -- Dan Mutchler | ARPA/Internet: mutchler@EBay.Sun.COM Sun Federal System Engineer | UUCP: ...!sun!mutchler -------------------------------------------------------------------------- Work hard. Play hard. Eat hard. Sleep hard. Grow big. Wear glasses, If you need them. -The Webb Wilder Credo