Preceptor has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: NFS locking with Fcntl
by Preceptor (Deacon) on May 10, 2016 at 11:25 UTC | |
by QM (Parson) on May 10, 2016 at 12:43 UTC | |
by Preceptor (Deacon) on May 10, 2016 at 15:35 UTC | |
|
Re: NFS locking with Fcntl
by taint (Chaplain) on May 10, 2016 at 13:19 UTC | |
by Preceptor (Deacon) on May 10, 2016 at 15:42 UTC | |
by taint (Chaplain) on May 10, 2016 at 18:31 UTC | |
|
Re: NFS locking with Fcntl
by mr_mischief (Monsignor) on May 10, 2016 at 22:04 UTC | |
by taint (Chaplain) on May 11, 2016 at 01:00 UTC | |
by Preceptor (Deacon) on May 19, 2016 at 13:05 UTC |