Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello Monks, I'm hoping this isn't too stupid a question. I have been trying to test (for a new system) locking files on NFS. My problem is - I'm having a real difficulty untangling what is a good way of accomplishing it - I've tracked down fcntl, and flock.

So is anyone able to give me a pointer in how this is done 'right'? All I really need is to be able to create and lock a test file (twice, so I can check if the lock is 'working'), and can run on multiple instances/hosts. I am aware that this is implementation dependent - but this is as much to test if I _can_ on our implementation, as anything else.

Thus far, I've got as my tests:

#!/usr/bin/env perl use strict; use warnings; use Fcntl qw ( :flock ); open ( my $lock_this, '>', 'lockfile_flock' ) or die $!; print "Enter to lock\n"; <>; print "Requesting EX lock\n"; flock ( $lock_this, LOCK_EX ); print "Lock acquired\n"; print "Enter to release\n"; <>; flock ( $lock_this, LOCK_UN ); print "Lock released\n";

I'm trying to do the same with fcntl, but am being flummoxed a bit by references to pack and flags. Is anyone able to give me an example of how using "fcntl" to lock a file is supposed to look in perl?


In reply to NFS locking with Fcntl by Preceptor

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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others chanting in the Monastery: (3)
    As of 2025-06-15 14:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.