I need a SysV select()

James DaSilva jds at mimsy.UUCP
Wed May 18 02:26:19 AEST 1988


In article <7904 at brl-smoke.ARPA> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <9738 at sol.ARPA> jpayne at 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 at cs.umd.edu
      "Stand on each other's shoulders, not on each other's toes."



More information about the Comp.unix.wizards mailing list