Is a successful call to write(2) atomic?

Ronald F. Guilmette rfg at
Wed Jun 16 23:18:24 UTC 2021

In message <af9666f4-f327-432e-5b10-100557aa9cf5 at>, 
Kurt Hackenberg <kh at> wrote:

>Since you only open the file once, you should seek to end of file before 
>each write, as somebody else pointed out. You should do that seek, and 
>the write, while holding the file lock. That is:
>   lock file
>   seek to EOF
>   write
>   unlock file
>Does your code do that?

Nope.  I'll give it a try.  Thanks!

>The reason, of course, is that some other process could move end of file 
>out from under you while you do not hold the file lock.

Sounds entirely plausible.


More information about the freebsd-questions mailing list