in reply to Re: Re: locking a NFS file
in thread locking a NFS file
Personally I've used the technique described in Stevens' Unix Network Programming, which goes something like this:
Create a temp file on the NFS partitionReleasing a lock is simply a matter of deleting the lock file.
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
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
|
|---|