Is a successful call to write(2) atomic?

Kurt Hackenberg kh at
Wed Jun 16 00:34:15 UTC 2021

On 2021/06/15 18:43, Steve O'Hara-Smith wrote:

>> No, write(2) is not guaranteed atomic, and that's not obvious. Probably
>> a lot of people have learned that the hard way.
> 	Strangely (after posting a confident no it isn't guaranteed) I
> noticed this in write(2) which implies that it is guaranteed to write a
> contiguous block (at least for seekable objects):
> --------------
> On objects capable of seeking, the write() starts at a position given
> by the pointer associated with fd, see lseek(2).  Upon return from write(),
> the pointer is incremented by the number of bytes which were written.

That's talking about the pointer associated with the file descriptor. 
The system call fork() gives the child process *copies* of file 
descriptors. Not clear whether that pointer is also copied.

That man page doesn't discuss concurrent writes; I wouldn't swear to the 
exact meaning of that quote.

I think Ronald has effectively written test code, and got garbled output.

More information about the freebsd-questions mailing list