Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!ux1.cso.uiuc.edu!tank!gargoyle!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.wizards Subject: Re: SYS V Rel 3.2 (3B2) asynchronous reading from two or more inputs Keywords: asyncronous SYSV 3B2 Message-ID: <1990Feb22.040307.3271@chinet.chi.il.us> Date: 22 Feb 90 04:03:07 GMT References: <244@imspw6.uunet.UUCP> Reply-To: les@chinet.chi.il.us (Leslie Mikesell) Organization: Chinet - Chicago Public Access UNIX Lines: 27 In article <244@imspw6.uunet.UUCP> pryor@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@chinet.chi.il.us