Path: utzoo!attcan!uunet!husc6!cmcl2!nrl-cmf!ames!killer!netsys!cucstud!c3pe!c3engr!charles From: charles@c3engr.UUCP (Charles Green) Newsgroups: comp.unix.wizards Subject: Re: I need a SysV select() Summary: Multiplexor processes writing a shared pipe read by main process Message-ID: <2643@c3engr.UUCP> Date: 21 May 88 02:30:52 GMT References: <9738@sol.ARPA> <7904@brl-smoke.ARPA> <11536@mimsy.UUCP> Reply-To: charles@c3engr.UUCP (Charles Green) Organization: C3, Inc. Engineering Division, Herndon, VA 22070-5201 Lines: 33 In article <11536@mimsy.UUCP> jds@mimsy.umd.edu (James da Silva) writes: >>In article <9738@sol.ARPA> jpayne@cs.rochester.edu (Jonathan Payne) writes: >>>I want to get input >>>from either the keyboard or from some other file description. I don't >>>want to sit around polling the two, because that would be ridiculous. >The natural way to handle this in System V is to use two processes, each of >which is waiting on one file descriptor. You can then use shared memory >and/or signals, semaphores or message queues to get the data around, to taste. My favorite solution is to have several small "multiplexor" processes, all identical but exec()ed with a unique numeric argument, reading their respective stdins and all writing into the same pipe that's read by the main process. When one of the multiplexor processes completes a read(), he does a single write() to the pipe containing his unique ID, a byte count, and the data. The main process sleeps on a read() of the pipe of a size sufficient to pick up the "header" (ID and byte count). When he gets one, he issues another read() to pick up the data. This scheme works because a write() to a pipe is atomic; data from the other multiplexor processes won't be interspersed with it (as opposed to TTYs...) However, you have to be able to accept data from all "channels" simultaneously; you can't selectively read data from one channel and not another. fd >----> [mux] >-- \ fd >----> [mux] >---+--> (pipe) >--> [main process] / fd >----> [mux] >-- -- #ident "@(#).signature 1.5 :~charles/s..signature 04/27/88 21:40:43" charles@c3pe.UUCP charles_green%c3gate@c3pe