Path: utzoo!utgpu!attcan!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.unix.questions Subject: Re: Are terminal writes atomic? Summary: No!! writes to ttys are NOT ATOMIC. Message-ID: <1247@virtech.UUCP> Date: 8 Oct 89 02:26:54 GMT References: <-286379999@hpcupt1.HP.COM> <1118@cs.yale.edu> <186@promark.UUCP> <191@promark.UUCP> Organization: Virtual Technologies Inc Lines: 54 In article <191@promark.UUCP>, mark@promark.UUCP (Mark J. DeFilippis) writes: > In article <19972@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > > In article <186@promark.UUCP> mark@promark.UUCP (Mark J. DeFilippis) writes: > > >How about we take this further. The answer to this question is an > > >undocumented feature of write() under Unix. Several Authors note this > > > > Of course, it might be undocumented because it is false. > > > > On Berkeley systems (4BSD, at least), writes to character devices are > > Indeed I should have qualified my statement, however almost everyone is > familiar with Rochkind's _Advanced Unix Programming_ book, and they are > aware it is a SYSTEM V book, not a 4BSD Unix book. > Under System V, it is a known undocumented item. By undocumented, I mean > it was left out of the documentation and under ALL true Unix System V systems, > atomic writes at the system call level are guaranteed. NO THIS IS NOT TRUE. Writes are not atomic. To prove the point I threw the following example program together: #define BUFSIZE 2048 main() { char buffer[BUFSIZE+1]; int i; if( fork() == 0 ) { for(i=0; i < BUFSIZE; i++) buffer[i] = '0'; buffer[i++] = '\n'; write(1,buffer,i); exit(0); } for(i=0; i < BUFSIZE; i++) buffer[i] = '1'; buffer[i++] = '\n'; write(1,buffer,i); exit(0); } On my "true" system V (AT&T System V/386 Release 3.2) this resulted in mixed output. I don't care what someones book says, the real thing says that it is not atomic. Try this on your system and see what you get. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+