in reply to Safe to open+close for every write, without locking?

Opening with >> corresponds to an fopen(3) mode of "a". My fopen(3) man page says:

Opening a file in append mode (a as the first character of mode) causes all subsequent write operations to this stream to occur at end-of-file, as if preceded the call:

    fseek(stream,0,SEEK_END);

I suspect that fopen(..., "a") accomplishes this by using the O_APPEND flag of open(2) on modern Linux systems. On such systems, the implied seek & write would a single atomic operation (ignoring NFS).

Replies are listed 'Best First'.
Re^2: Safe to open+close for every write, without locking?
by sedusedan (Pilgrim) on Dec 21, 2012 at 06:05 UTC

    Interesting. However, without closing+reopening after each write (i.e. each process opens in "a" mode + writes 100k times + closes) there is clobbering.