On Mon, Apr 11, 2011 at 23:37, Parag Kalra <paragka...@gmail.com> wrote:
> Hi,
>
> I was just exploring File::NFSLock to lock files on the NFS server but seems
> like its not working. It ends up creating stale files and only option left
> is to abort the script. I am testing it on NFSv3
>
> Anybody had any success in using this module?
>
> Here is my sample code.
>
> use strict;
> use warnings;
>
> use File::NFSLock qw(uncache);
> use Fcntl qw(LOCK_EX LOCK_NB);
> print "Please enter the file to be locked:\n";
> chomp(my $file = <STDIN>);
> open my $fh, '>', $file or die $!;
> print $fh "Hello World";
> print "Please try to write to the file\n";
> my $wait = <STDIN>;
> #my $lock = File::NFSLock->new($file,LOCK_EX|LOCK_NB,10*60,30*60);
> my $lock = File::NFSLock->new($file,LOCK_EX,10*60,30*60);
> print "File is now locked. Now again try to write to the file\n";
> $wait = <STDIN>;
> print "Lock operation over\n";
>
> ~Parag
>

Hmmm, works pretty well for me on Solaris 9 and Solaris 10 where the
lock is on an NFS partition that all three machines share.  I don't
think I've had any stale lock problems (perhaps only one) and no hung
processes and I no longer experience text file corruption that I was
experiencing previously when more than one person wanted to write to
the same text file at the same time.  Make sure that the lock file is
on the NFS partition.

Ken Wolcott

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to