Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
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 browsing the Monastery: (10)
As of 2024-05-21 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found