Tty queues

Henry Spencer henry at utzoo.UUCP
Thu Mar 5 07:52:23 AEST 1987


> It's not clear where the stuff gets mixed up.  We're guessing that the 
> problem is in printf, that printf makes multiple calls to write()...

Could be, depends on *exactly* what's been done to your printf.  Old ones
generally write a character at a time, most new ones try to do only one
write (but often have only finite buffering available).

> ...If I made just one call to write with the whole string, would the problem
> go away?  Or is it something like the copy getting interrupted by
> new tty i/o (I hope not).  

You're not going to like this, but in general there is *no* guarantee about
the order or interleaving of tty output coming simultaneously from multiple
sources.  None.  The system will *try* to complete a write as an atomic
entity, but there is only a finite amount of buffering between the write
and the device, and if there's no room, the write will have to wait.
If more than one write is waiting for buffer space, which one gets first
grab when more space appears is unpredictable.  That's my recollection,
anyway.  Much depends on details, which differ between Unix variants.
-- 
"We must choose: the stars or	Henry Spencer @ U of Toronto Zoology
the dust.  Which shall it be?"	{allegra,ihnp4,decvax,pyramid}!utzoo!henry



More information about the Comp.unix.wizards mailing list