-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 At some point hitherto, Jerry Feldman hath spake thusly: > I do not recommend using flock(2). I concur with Jerry. And I do so because W. Richard Stevens gives the same advice. Basically, implementations of flock are non-standard, often buggy, and often just plain unavailable. Locking with fcntl() is standardised in POSIX.1 and available on virtually all modern Unix systems. > I'm not 100% sure of this in Linux, but flock(2) is an advisory lock, so > that anyone can modify the file regardless of the lock state. On Linux, flock is an advisory lock, but fcntl also is an advisory lock (usually). You *can* implement mandatory (i.e. kernel-enforced) locking. SVr3 introduced mandatory locking using fcntl by mucking about with permission bits. Linux implements this same mandatory locking mechanism[1]. However, mandatory locking too is not with out it's own problems[2]... > I strongly recommend that you use fcntl(2) as your lock mechanism as it is > semanticly and syntacticly standard across platforms. It locks across NFS. > You can also lock a portion of a file. While locking using fcntl() is generally superior to locking via flock() and some other methods, it is worth noting that it too is not without its problems. Most of these are with older, buggy implementations of lockd and statd, which AFAIK are mostly fixed on more recent releases of U*ixes. Basically, locking sucks. Locking with fcntl() just sucks the least on most platforms. - ----- footnotes: 1. For details of the implementation, see the documentation in the kernel source tree in /Documentation/mandatory.txt 2. See W. Richard Stevens, _Advanced Programming in the Unix Environment_, pp 376-8. [If you write C code on Unix systems, you really should read this book cover to cover. :) ] - -- Derek Martin ddm@pizzashack.org - --------------------------------------------- I prefer mail encrypted with PGP/GPG! GnuPG Key ID: 0x81CFE75D Retrieve my public key at http://pgp.mit.edu Learn more about it at http://www.gnupg.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8v3I/djdlQoHP510RAjycAJ9UZX472xrzcyLWEWyU5EDfMfxsawCfVs7a FRZnMscTs+23adZPJJN4Rc8= =k1qs -----END PGP SIGNATURE-----