Path: utzoo!utgpu!watserv1!watmath!att!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!swrinde!mips!sgi!shinobu!odin!odin.corp.sgi.com!tomw From: tomw@orac.esd.sgi.com (Tom Weinstein) Newsgroups: comp.unix.internals Subject: Re: Can Unix sleep in terms of mili/micro? Message-ID: Date: 10 Sep 90 14:38:44 GMT References: <24437@adm.BRL.MIL> <11899@chaph.usc.edu> Sender: news@odin.corp.sgi.com (Net News) Reply-To: tomw@esd.sgi.com Organization: Silicon Graphics Inc. Lines: 33 In-Reply-To: tli@phakt.usc.edu's message of 10 Sep 90 06:43:42 GMT In article <11899@chaph.usc.edu>, tli@phakt.usc.edu (Tony Li) 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. > > BSD derived systems provide usleep(3) which does what you want. Yuck. Ick. Ptui. usleep is really pretty icky because it uses itimers, and the system call overhead (4 of them!) can seriously destroy the accuracy of your timing. A much better idea is to use something like this: { static struct timeval tv; tv.tv_sec = usecs / 1000000; tv.tv_usec = usecs % 1000000; select(0, 0, 0, 0, &tv); } This uses only one system call instead of the 4 of usleep, and it doesn't use itimers so it won't screw up programs that use them for other things. -- Tom Weinstein Silicon Graphics, Inc., Entry Systems Division, Window Systems tomw@orac.esd.sgi.com Any opinions expressed above are mine, not sgi's.