I think you're confusing things. File locks in POSIX do not influence the ability to open files at all. File locks only influence the ability to create other locks.

In other words, file locks are normally* cooperative, if some program doesn't try to lock a file, it can bypass all locks.

In other words again, my sample code is correct; you open the file for append (or you can use some other non-destructive open) and lock after that (but before writing).

If this doesn't help, please show some code or explain what you're trying to do, because right now it just looks like you don't know what file locks do and don't do on UNIX.

* Update: some unix systems also provide mandatory locks. I'm ignoring those since a) they're not portable and b) I don't like mandatory locks.


In reply to Re^5: File locking by Joost
in thread File locking by Nalina

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.