Can Unix sleep in terms of mili/micro?
Dan Mutchler
mutchler at zule.EBay.Sun
Wed Sep 12 07:05:10 AEST 1990
In article <84 at dlss2.UUCP> james at dlss2.UUCP (James Cummings) writes:
In article <24437 at adm.BRL.MIL> 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:
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 at 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
More information about the Comp.unix.internals
mailing list