Can Unix sleep in terms of mili/micro?
Sandeep Mehta
sxm at bebop.Philips.Com
Thu Sep 13 23:36:08 AEST 1990
james at dlss2.UUCP (James Cummings) writes:
TAYBENGH%NUSDISCS.BITNET at 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:
sleep_less_than_sec(x)
int x;
{
int i;
for (i = 0;i <= x;i++)
;
}
For many (obvious) reasons a dummy loop is not the best idea. Besides
you may not have a real time clock in your UNIX box, e.g., Sun 3's (at
least the ones I use) use the Intersil 7170 "real-time" clock in 100 Hz
periodic mode, giving a resolution of only 10 milliseconds. Using the
clock(3C) function yields CPU time used only up to a 16.667 milliseconds
accuracy. Sun 3 (SunOS 4.0) getrusage() assumes tick intervals of
20msec, for Sun 4's 10msec. I know that struct timerval' has a "usec"
field but of course the value is hardware dependent.
You might write your own little assembler routine to use a spare counter
or something (not advisable :-)) which will suffer from all the
restrictions of the process that uses it. I know that some folks @
Berkeley have a real-time timer facility for Sun 3's under SunOS and
it's (h'ware + s'ware) pretty cheap. But then again, is UNIX/SunOS
real-time ?
Don't know if I answered the question either ?
sandeep
--
sxm at philabs.Philips.Com "Jazz is Happiness" - Le Sony'Ra
More information about the Comp.unix.internals
mailing list