Hi mightyMrJawz,

I could have up to 50 servers trying to determine if the file exists

To be honest, it really sounds like you need a database instead. Update: Note this quote from the File::NFSLock documentation: "Locks are not necessarily obtained on a first come first serve basis. Not only does this not seem fair to new processes trying to obtain a lock, but it may cause a process starvation condition on heavily locked files."

changed the code from "LOCK_EX" to "LOCK_NB"

AFAIK LOCK_NB is an option that is needed in addition to either LOCK_EX or LOCH_SH (Update: see also flock). See the example code at the top of File::NFSLock (I trimmed it down slightly):

use File::NFSLock; use Fcntl qw(LOCK_EX LOCK_NB); my $file = "somefile"; if (my $lock = new File::NFSLock { file => $file, lock_type => LOCK_EX|LOCK_NB, blocking_timeout => 10, # 10 sec stale_lock_timeout => 30 * 60, # 30 min }) { open(FILE, "+<$file") || die $!; # or open it any way you like # ... $lock->unlock(); }else{ die "I couldn't lock the file [$File::NFSLock::errstr]"; }

Instead of dieing, you would let your code continue.

BTW, there seems to be something wrong with the <code> tags in your post. Perhaps you could edit your node to fix that.

Hope this helps,
-- Hauke D


In reply to Re: NFSLock - Continue in code if another server already has lock on file (updated) by haukex
in thread NFSLock - Continue in code if another server already has lock on file by mightyMrJawz

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.