Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k
edited tags
Link
Steven D
  • 47.6k
  • 15
  • 123
  • 117
Source Link
Jmoney38
  • 576
  • 2
  • 5
  • 13

flock(2) versus fcntl(2) over a NFS

The Perl 5.x documentation states that its implementation of flock(..) will use one of the following native calls, starting at 1 and working toward 3 if unavailable:

  1. flock(2)
  2. fcntl(2)
  3. lockf(3)

That's fine. However, you may have noticed their disclaimer that flock(2) should not be used over a NFS. The doc suggests using a -Ud_flock flag to force Perl to use flock(2). The man page of flock(2) (on Redhat) states a similar disclaimer about NFS issues.

My question is, why!?!? I can't seem to find an in-depth article or explanation of WHY flock(2) is unsafe over a NFS.

I've written several test scripts in C and Perl, on both Redhat (where flock(2) is being used) and on Solaris (where fcntl(2) is being used). I ran strace/truss to ensure that Perl was indeed using flock(2) and fcntl(2) respectively. I could not replicate any issues where a lock was not being honored! What gives??