Is write(2) "atomic" ?

Naim Abdullah naim at eecs.nwu.edu
Thu Jul 14 17:32:04 AEST 1988


Chris Torek pointed out that the fact that concurrent writes may
result in loss of data, is due to a bug in 4.2BSD. The bug persists
in 4.3BSD (at least in Mt. Xinu's 4.3+NFS). 

However, I was able to solve the original problem by using O_APPEND
when I open(2)'ed the output file. This seems to result in atomic
writes. Thanks to haynes at ucscc.ucsc.edu for this suggestion. He also
pointed out that the 4.3bsd login(1) opens wtmp using O_APPEND as login faces
the same problem of multiple concurrent writers to the same wtmp
file (when many people are logging in and out at the same time).
I just checked our System V rel 3.1 sources and the system V login
fseeks before fwriting to wtmp so I imagine it will suffer from this
problem too.


		      Naim Abdullah
		      Dept. of EECS,
		      Northwestern University

		      Internet: naim at eecs.nwu.edu
		      Uucp: {oddjob, chinet, gargoyle}!nucsrl!naim



More information about the Comp.unix.wizards mailing list