intermachine flocking

Dominic Mitchell dom at
Tue Dec 13 16:38:02 GMT 2005

On Tue, Dec 13, 2005 at 04:24:51PM +0000, Simon Wistow wrote:
> We have a farm of machines which will have access to a file. We only 
> want one of the machines accessing that file at once - if a process 
> cannot get a lock on the file then it should exit immediately otherwise 
> it shoudl write the necessary number of times to the file and then exit.
> Of course flock() doesn't work across NFS. Is the only solution to this 
> a flock daemon?

If you're in Perl, flock() is probably implemented using fcntl(), which
is supported over NFS.  Run strace over a test script to verify.

If it's not, then you need to do jiggery pokery with lockfiles.  This
involves, IIRC, creating a temp file using your hostname, pid, current
time, and $i++.  You then have to call link() and then stat() in order
to check that the number of links is correct.  Or something like that...
Basically you want to look like a Maildir.

This seems to describe what I'm thinking of:


More information about the mailing list