Scanning stdin with no pause
Geoff Kuenning
geoff at desint.UUCP
Tue Dec 25 05:30:23 AEST 1984
>> I am working with V7 UN*X. I need a way to scan the standard input
>> stream for a character, but not wait.
>
>This is not supported by 7th Edition UNIX. You need to add something
>to your kernel to do this directly; the Rand Corp. empty() call has
>been distributed by USENIX a long time ago, and more recent approaches
>include VTIME,VMIN in AT&T UNIX Systems III & V and select() in 4.2BSD.
Also the FIONREAD ioctl found in 4.1BSD and 4.2BSD. If you have access
to BSD code, you may be able to copy that one, since it isn't complex code.
I prefer the idea of doing it with an ioctl anyway.
>A groady way to accomplish this on any UNIX is to use a second process
>that communicates with the controlling process via a pipe.
An even grodier way is to use a 1-second alarm to blast you off the read if
there is nothing coming. This is obviously not much good unless it is the
unusual case (e.g., a missed packet in a packet protocol).
A final note. If part of your concern is packet protocol efficiency, some
people have hacked V7 uucp to do the following: if the last read returned
only 1 character, they sleep for some baud-rate-dependent time (calculated to
be approximately one packet time) before they issue another read. This
markedly improved CPU availability on some V7 systems without affecting uucp
performance.
--
Geoff Kuenning
...!ihnp4!trwrb!desint!geoff
More information about the Comp.unix.wizards
mailing list