I have used flock() and fcntl() in the past, but I've always been concerned that behavior is undefined or problematic for some older versions of Linux.
I need a solution that is compatible with older Linux-es (say, 2.6.18 or better), and NFS 3+.
Will flock() and/or fcntl() work consistently under those circumstances, or do I need to resort to open (.... O_EXCL) to guarantee atomicity?
You definitely cannot expect flock() to work with NFS. fcntl() with F_SETLK has a decent chance of working, with caveats if you have multiple uses in one process: http://0pointer.de/blog/projects/locking.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With