Re: Write is not atomic?

From: Max Filippov
Date: Mon Oct 15 2012 - 19:42:43 EST


On Tue, Oct 16, 2012 at 3:24 AM, Philippe Troin <phil@xxxxxxxx> wrote:
> On Tue, 2012-10-16 at 10:13 +1100, Dave Chinner wrote:
>> On Mon, Oct 15, 2012 at 11:36:15PM +0200, Juliusz Chroboczek wrote:
>> > The following fragment of code
>> >
>> > int fd;
>> > fd = open("exemple", O_CREAT | O_WRONLY | O_TRUNC, 0666);
>> > fork();
>> > write(fd, "Ouille", 6);
>> > close(fd);
>
> can be replaced with:
>
> int fd;
> fd = open("exemple", O_CREAT | O_WRONLY | O_TRUNC | O_APPEND, 0666);
> fork();
> write(fd, "Ouille", 6);
> close(fd);

Fails the same way as the original. I guess O_APPEND doesn't work this way
for writes to the shared file descriptor.

--
Thanks.
-- Max
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/