How to do a non-blocking write of more than one char?

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Wed Jan 17 10:08:35 AEST 1990


I'm trying to write a ``multitee'' program so that, e.g.,

  multitee 0:6,7 6:1

would send all input from fd 0 to fd 6 and fd 7, while sending all input
from fd 6 to fd 1. It's a trivial problem, except that multitee should
do its best to never block on writes. (Otherwise it could enter a deadlock
with another process.) Buffering is easy, but how to avoid blocking?

One correct answer is to always write just one character per write()
call. Unfortunately, this usually forces a hellish overhead.

Another answer is to use fcntl() and set FNDELAY on the descriptor.
Unfortunately, this doesn't just affect the descriptor; it affects the
entire open file, including possibly other processes. (This is the real
problem.)

Another answer is that multitee should fork into separate processes,
one for each input descriptor. This works and solves the flow control
problems, but it's not very polite to other processes unless the system
supports threads.

In article <2816 at auspex.auspex.com> guy at auspex.auspex.com (Guy Harris) writes:
> >C'mon, guys, this is a simple question!
> And it may have a simple answer like "sorry, you can't do it".

I guess it's a good question, then...

---Dan



More information about the Comp.unix.questions mailing list