cat /dev/ttya > /dev/null &

David Steffens harvard!eplunix!das at a.cs.uiuc.edu
Fri Sep 1 14:38:26 AEST 1989


In article <815 at brazos.Rice.edu>
number1!perl%step at uunet.uu.net (Robert Perlberg) writes:

> This is a very old problem found on many UNIX systems.
Possible, but I doubt it.

> By the time your application is finished writing and closes the port,
> there is still quite a bit of data in the queue which has not yet gone out.
> Whatever data is still in the queue when the port is closed is thrown away.

Any UNIX on which this really is true is just plain _broken_.  The tty
driver is responsible for getting the chars out even _after_ the process
has gone away.

> This results in the "missing pages" problem reported by many lpr users.
Actually, I believe the problem is caused by _re-opening_ the tty line
before all of the output from the previous write has drained.

I've seen a similar problem on a hard-copy console at boot time -- the
messages from /etc/rc are truncated.  The tty driver is apparently
flushing all pending output when the _first_ open occurs on a line.  In
both the case of lpr and /etc/rc messages, no other process has the line
open for write, so every open is the first one.  Ergo, it is the "write...
last close... first open" cycle which tickles the bug.

> The solution is to make sure that the tty port is not
> closed until after all of the data has been transmitted.

You are correct... at least until Sun fixes the _real_ bug.  However, a
better way of describing the required work-around is: make sure there is
_at least one_ writer active on the line at all times.

{harvard,mit-eddie,think}!eplunix!das	David Allan Steffens
243 Charles St., Boston, MA 02114	Eaton-Peabody Laboratory
(617) 573-3748				Mass. Eye & Ear Infirmary



More information about the Comp.sys.sun mailing list