SYS V Rel 3.2 (3B2) asynchronous reading from two or more inputs

Leslie Mikesell les at chinet.chi.il.us
Thu Feb 22 15:03:07 AEST 1990


In article <244 at imspw6.uunet.UUCP> pryor at uunet.UUCP (Paul Pryor) writes:

>		read from pipea using read(2). If there are bytes
>		returned from read(), it writes them out to stdout

>		read from stdin using read(2). If there are bytes
>		returned from read(), it writes them out to pipeb

>From above algorithm, I immediately ran into two serious problems:

Why not fork another process for one of these jobs?  Then you can
forget the O_NDELAY stuff and let the read()'s block when there is
nothing to do and stop hogging the CPU. 

>I didn't want to put in sleep()'s because I wanted to create time stamps
>for groups of bytes read in from either sources.

A one second sleep() in the busy loop will make the difference between
about 4 syscalls/sec (no real problem) and the hundreds (all the CPU
can handle) that you get without it.  If you need < 1 sec. granularity
then you can either run two processes or find a way to block for a 
shorter time.  Some SysV's have nap(), or you could play games with
a read() on an unused ttyline with VMIN/VTIME set appropriately - or if
stdin happens to be a tty you can do it directly.

Les Mikesell
  les at chinet.chi.il.us



More information about the Comp.unix.wizards mailing list