in reply to Re^4: Writing to a log file without colliding
in thread Writing to a log file without colliding
syswrite might be atomic, but that doesn't buy you anything, because open is still a separate step. Another process may have appended data to the file between your opening it and appending to it. Your file pointer will not advance to reflect the new end of the file, so you will overwrite that processes' data.
The only safe way to append to a file is to open it, obtain an exclusive lock, seek to its end, and then write. That seeking step is necessary exactly because of the above issue: between opening the file and getting a lock on it, someone else may have appended data to it.
What I said still stands: there is no way around locking.
Makeshifts last the longest.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Writing to a log file without colliding
by dave_the_m (Monsignor) on Aug 17, 2004 at 12:52 UTC | |
by Aristotle (Chancellor) on Aug 17, 2004 at 15:06 UTC |