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?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|