Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!umd5!mimsy!jds From: jds@mimsy.UUCP (James DaSilva) Newsgroups: comp.unix.wizards Subject: Re: I need a SysV select() Summary: use two communicating processes Message-ID: <11536@mimsy.UUCP> Date: 17 May 88 16:26:19 GMT References: <9738@sol.ARPA> <7904@brl-smoke.ARPA> Reply-To: jds@mimsy.umd.edu (James da Silva) Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 36 In article <7904@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn) 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. > >If you set MIN and TIME to 0 in the terminal handler, then an attempt >to read from the terminal with no data available will return immediately. >There is nothing analogous for ordinary files. That's just his point, Doug. Sure, once you call ioctl to set things up to return immediately if no data is present, the polling loop looks something like this: for(;;) { if(size1 = read(fd1,buffer1,MAX)) do_something_with(buffer1,size1); if(size2 = read(fd2,buffer2,MAX)) do_something_with(buffer2,size2); } (Ignore the fact that this simple example doesn't handle error returns from read. You get the point). This REALLY eats CPU time. If nothing is pending, it will use as much CPU as the kernel is willing to give it. Not very friendly. 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. - Jaime ---------------------------------------------------------------------- usenet: uunet!mimsy!jds James da Silva internet: jds@cs.umd.edu "Stand on each other's shoulders, not on each other's toes."