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

In reply to Re: (OT?) File Locking by {NULE}
in thread (OT?) File Locking by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.