Re: how to write to a file without race condition
From: James (jas_at_spamcop.net)
Date: Sun, 18 Jul 2004 11:44:21 +0100
On 17 Jul 2004 23:08:30 GMT, Casper H.S. Dik <Casper.Dik@Sun.COM>
>James <firstname.lastname@example.org> writes:
>>No, each of them will atomically seek to the current EOF, append their
>>data, then the next one will write at the new EOF. They won't
>>overwrite each other unless they're running over NFS (which introduces
>>a race condition) or they used lseek with an explicit offset rather
>Why do you believe that lseek(..., SEEK_END) has this magic
That's what Alex Colvin said earlier in the thread. It *doesn't* have
this property (which is hardly "magic", since it amounts to setting
the O_APPEND flag!), but until I checked for myself his explanation
seemed reasonable, particularly in the absence of any challenge until
yours. (James Antill *agreed* with it, then changed his mind
> lseek sets the file pointer and the only thing "SEEK_END"
>does is to set the file pointer relative to the current end.
Correct. As I said earlier, to achieve the result described you need
to set O_APPEND rather than using lseek().