in reply to (OT?) File Locking

Hi AM,

Different operating systems hande this in different ways. I'm am almost 100% positive that on any UNIX like operating system the append writes are atomic. Meaning as long as you are writting in append mode you don't have to explicitly lock the file. The operating system will make sure that the write from one process will complete before the write from another process begins. From the open() man page (on Mandrake 8.1):

The file is opened in append mode. Before each write, the file pointer is positioned at the end of the file, as if with lseek. O_APPEND may lead to corrupted files on NFS file systems if more than one process appends data to a file at once. This is because NFS does not support appending to a file, so the client kernel has to simulate it, which can't be done without a race condition
I take this to mean that with the exception of writes to an NFS mounted file system writes in append mode happen atomically and each write should finish before the system allows another to begin. This means your output may be intermingled with other output, but not corrupted.

The only link I could find that explicitely states this is here - a manpage for fopen():

Opening a file with append mode (a as the first character in the mode argument) causes all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to fseek(3S). If two separate processes open the same file for append, each process may write freely to the file without fear of destroying output being written by the other. The output from the two processes will be intermixed in the file in the order in which it is written.
Sorry this is vague, but I hope it helps. I know I read this somewhere - I just wish I could recall where for you. Good luck,
{NULE}
--
http://www.nule.org