Are terminal writes atomic?

Joel Spolsky spolsky-joel at CS.YALE.EDU
Mon Oct 2 06:56:50 AEST 1989


In article <-286379999 at hpcupt1.HP.COM> stratton at hpcupt1.HP.COM (Jim Stratton) writes:
>I have two processes doing simultaneous output to the same terminal using the
>write system call.  Assume A does a write of 10 bytes while B does a write
>of 30 bytes.  Can I be assured that A's and B's output will not be inter-
>mixed?  I understand that for pipes, they won't be mixed.  How about terminals?
>--
>Jim Stratton		hplabs.hp.com!hpcupt1!stratton


I think this is safe. A while ago I wrote a little program that runs
on a Unix host, and puts the time, date, and warns you if you get mail
in the status line of TVI950's or VT100's. This program runs quitely
in the background, and every once in a while sends the necessary
string to the terminal. Under extensive testing, it never interfered
with whatever foreground process was running, even when it had to
write a whole 80 character string to the status line every second. The
write() commands were preserved atomically.

Now, this is on Sun-OS 4.0, it might not work on your system, and I
don't know how to "prove" that it always works, but it has for me.

+----------------+----------------------------------------------------------+
|  Joel Spolsky  | bitnet: spolsky at yalecs.bitnet     uucp: ...!yale!spolsky |
|                | internet: spolsky at cs.yale.edu     voicenet: 203-436-1538 |
+----------------+----------------------------------------------------------+
                                                      #include <disclaimer.h>



More information about the Comp.unix.questions mailing list