[comp.unix.i386] nap in Sys V

rick@pcrat.UUCP (Rick Richardson) (04/06/89)

>:>>AT&T sucks for not having a sub-second clock interval.  Although XENIX nap()
>:>>is anemnic compared to BSD ftime().
>:>
>:>Which, of course, means that SysV missed the boat.  Except for SysV R3.2,
>:>which of course includes nap().

If you have SVR3.2 there is a nap() in /lib/libx.a.  But if you
are at SVR3.0 or .1 level, all is not lost.  In fact, any version
of UNIX that has the STREAMS modules configured can do a nap().

Here's how to do nap portably across all UNIXes with STREAMS:

	#include <stropts.h>
	#include <poll.h>
	nap(milliseconds)
	int	milliseconds;
	{
		struct pollfd	dummy[1];

		poll(dummy, 0L, milliseconds);
	}

By telling "poll(2)" to poll exactly zero stream fd's, it does
exactly that.  Since there is no way for any input to arrive
on zero fd's, poll just waits the timeout value.  The timeout
is spec'ed in milliseconds, but is probably subject to the
granularity of clock ticks on your computer (100/second on a 386).


-- 
Rick Richardson | JetRoff "di"-troff to LaserJet Postprocessor|uunet!pcrat!dry2
PC Research,Inc.| Mail: uunet!pcrat!jetroff; For anon uucp do:|for Dhrystone 2
uunet!pcrat!rick| uucp jetroff!~jetuucp/file_list ~nuucp/.    |submission forms.
jetroff Wk2200-0300,Sa,Su ACU {2400,PEP} 12013898963 "" \d\r\d ogin: jetuucp

dwc@homxc.ATT.COM (Malaclypse the Elder) (04/07/89)

another way to do this is to write a pseudo-device driver
and use ioctl on that device to put an entry in the callout
table to wake itself up in N ticks.  then you can write a
user level nap() to hide all the ugliness.

or if you are uncomfortable with writing pseudo-device drivers,
then just reserve a tty line, open it, ioctl it into raw mode
and with a timeout value equivalent to the desired nap time and
do a read from that line.  again, once you know which tty line
is reserved for this, you can hide all the ugliness in a function
call.

danny chen
att!homxc!dwc

zeeff@b-tech.ann-arbor.mi.us (Jon Zeeff) (04/10/89)

If anyone missed it, I wrote and posted a nap() device driver for Sys V
awhile back.  Let me know if you want a copy.


-- 
  Jon Zeeff			zeeff@b-tech.ann-arbor.mi.us
  Ann Arbor, MI			mailrus!b-tech!zeeff