Er, as far as I understand the way you have it wont work. You are opening the file in overwrite mode, and since the open happens before the lock and probably that locks are advisory on your os, you just clobber the lockfile, so your follow up lock suceeds because the file you are locking is not the same one (anymore) as the one the other process has locked (which you just deleted but it is holding open anyway).

So you have to open the file with something else, maybe '>>' or maybe '+<'. Im sure the article by Dominus that was suggested will help you sort it out.

And you should know that locking semantics vary from OS to OS. On Unix they are advisory, on Win32 they are compulsary. So for instance, what you did above would work just fine on Win32, but not on Unix.


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Re: Lock Effectivity by demerphq
in thread Lock Effectivity by Gorby

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.