I'd like to use standard flock() locks on the files if possible, because of the nature of the application. The files I'm using aren't just internal files; they're files that other processes access too. Using a custom locking scheme would, unfortunately, defeat this mechanism.

I've come up with two other ideas; unfortunately, neither is particularly portable:

  1. Fork off a separate daemon on startup, and have the request forks pass the names of which files to lock/unlock to it. This daemon would then maintain the locks. Unfortunately, this method would only work on systems where locks are advisory (not Windows or OS/2), since otherwise I couldn't write to the file in the next request.

  2. Fork off a separate daemon on startup, and have the request forks pass file descriptors (using Socket::PassAccessRights) that they've locked, then pass them back for unlocking. Although this method seems more proper, it is no better than method 1 since Socket::PassAccessRights only works on *NIX systems, and according to the docs, doesn't work particularly well because the file descriptor passing code in the kernel is buggy.

    1. In reply to Re: Using flock() on files by SiMac
      in thread Using flock() on files by SiMac

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



    2. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
    3. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
    4. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
    5. Please read these before you post! —
    6. 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
    7. 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;
    8. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
    9. See Writeup Formatting Tips and other pages linked from there for more info.