Is a successful call to write(2) atomic?

Ronald F. Guilmette rfg at
Wed Jun 16 08:15:45 UTC 2021

In message <20210616091158.313f9d26a415bf42ee0ebf94 at>, 
Steve O'Hara-Smith <steve at> wrote:

>> I'll try both... O_APPEND, with and without locking... but it kind of
>> seems to me that if O_APPEND, by itself, were actually doing what the man
>> page says it does, then that alone ought to be enough to prevent garbling
>> of the output lines.
>	No, in the ABDEF example the ABC process calls write and finds the
>end of file and sets up ABC to be written there then the DEF process calls
>write and finds EOF when the A and B have been written out but not C however
>C gets written between the DEF process finding the end of file and writing
>D out so C gets written and then overwritten. The O_APPEND guarantee that
>the blocks are written contiguously starting at EOF is held but nothing
>prevents the blocks from two writers interleaving and writing over each

ACK.  Thank you.  I'll do both and hope for the best.


More information about the freebsd-questions mailing list