Well, this probably won't be helpful, but ...
flock is not going to save you if the 'other' apps won't play nice. Likewise, unless all your apps respect the SEMAPHORE flag (e.g.:
while ( -s $SEMAPHORE ) { print STDERR "lock found waiting\n" if $debug > 10; sleep 5; }
flocking it won't do much. Of course, this implies that $SEMAPHORE is a well known name (/tmp/myapp.lck), not /tmp/mlock$$.lck - unless other versions can predict the name and check if it exists, (I'm guessing $file is the useful name and the file that gets 'wiped' now and then) your lock/semaphore isn't going to help. It seems your code would allow 2 instances to mess w/ $file if they each had different $tempfile instances. It should be that they have one $SEMAPHORE to work w/, check the existence of, etc.

Sorry, I don't recall your other posts, but you might also do your self some good by having the 'rename' preceeded by a debug "about to rename $tempfile to $file (I'm $this instance)" so you can see who is doing the wiping in hopes of pinpointing where your lock/semaphore goes a stray. As I read it, though your flocking isn't really giving you exclusive access for multiple instances of that code, or for anybody else, unless they're using the same $tempfile.

a


In reply to Re: flock() ..I really need a hand .. please :) by a
in thread flock() ..I really need a hand .. please :) 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.