Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Exclusive locking of a file on an NFS filesystem

by rah (Monk)
on Jun 14, 2002 at 01:22 UTC ( [id://174388]=perlquestion: print w/replies, xml ) Need Help??

rah has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

Does anyone know of a way I can put an exlusive lock on a file in an NFS filesystem, shared by just a couple of nodes. I have two processes on boxes which have the FS mounted. Basically I want the first one there, to win exclusive access to the file.

I have super searched and googled and did come up with File::NFSlock, but the readme is rather terse. It mentions an exclusive mode, but I can't tell if it allows this lock on read. I am going to pull it down tomorrow and test. But I was wondering if any monks have done this. Can it be done?

  • Comment on Exclusive locking of a file on an NFS filesystem

Replies are listed 'Best First'.
Re: Exclusive locking of a file on an NFS filesystem
by SarahM (Monk) on Jun 14, 2002 at 12:07 UTC
    I've tried File::NFSlock, but it didn't work that well for me...It was great during my testing. But when actual workload hit it, the locking didn't detect the file as locked too many times to be useful and I ended up having messed up files.

    On Solaris, I've also turned on rpc.lockd and rpc.statd. This seemed to work, except when one of the boxes crashed. It took a couple of hours and several reboots of both boxes before my sys admin was able to clear the outstanding locks.

    Locking over NFS seems to be problematic at best.

Re: Exclusive locking of a file on an NFS filesystem
by Abigail-II (Bishop) on Jun 14, 2002 at 11:17 UTC
    Whether you can reliably lock a file over NFS depends on the implementation of NFS on the involved systems. In general, you should avoid using locking over NFS - it's certainly not going to be portable.

    Abigail

Re: Exclusive locking of a file on an NFS filesystem
by Anonymous Monk on Jun 14, 2002 at 01:30 UTC
Re: Exclusive locking of a file on an NFS filesystem
by robobunny (Friar) on Jun 14, 2002 at 12:39 UTC
    you might consider implementing something similar to what the 'lockfile' command that comes with procmail does, or using lockfile itself.
Re: Exclusive locking of a file on an NFS filesystem
by rah (Monk) on Jun 15, 2002 at 01:14 UTC
    Thanks all for your replies. I don't need to worry about poratability (for now anyway), and my set up will be relatively simple. Two linux boxes looking for a "command" file in a directory NFS mounted from an AIX box. The program picking up this file and passing it off to a FAX program will likely be perl. If one of the available modules looked to be feasible for this set up, I would try it. If not, there are a number of other approaches we could take, including something akin to what procmail does. In fact, it seems like we have implemented that scheme many times.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://174388]
Approved by IlyaM
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-12-12 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (65 votes). Check out past polls.