Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: locking a NFS file

by Helter (Chaplain)
on Oct 30, 2002 at 16:42 UTC ( [id://209137]=note: print w/replies, xml ) Need Help??


in reply to Re: locking a NFS file
in thread locking a NFS file

I did see that module, it seems like overkill (a little), and like I said using a module is not the best solution for my situation. You have my thanks Artist.

We are trying to play with fcntl in a test script, but can't get it do the right thing, we don't quite understand what parameters it needs.

So does anyone have experience using fcntl?

Replies are listed 'Best First'.
Re: Re: Re: locking a NFS file
by mpeppler (Vicar) on Oct 30, 2002 at 18:14 UTC
    AFAIK using fcntl to lock a file on an NFS partition either does not work at all, or is extremely iffy.

    Personally I've used the technique described in Stevens' Unix Network Programming, which goes something like this:

    Create a temp file on the NFS partition
    Try to link this temp file to a lock file (using the link() call)
    If the link fails with EEXIST someone else already has the lock, so sleep for a bit and try again
    If the link succeeds you've got your lock, so delete the tempfile
    Releasing a lock is simply a matter of deleting the lock file.

    As lock files don't get automatically cleaned up you in case of abnormal termination you have to add some form of timeout and stale lock handling.

    All in all I'd say that the NFSlock module suggested above is probably the best solution (unless you want to roll your own to work around new module installation issues...)

    Michael

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-20 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found