Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
File locking
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== {{Anchor|POSIX}}Problems === More than one process can hold an exclusive <code>flock</code> on a given file if the exclusive lock was duplicated across a later <code>fork</code>. This simplifies coding for network servers and helps prevent race conditions, but can be confusing to the unaware. Mandatory locks have no effect on the <code>unlink</code> system call. Consequently, certain programs may, effectively, circumvent mandatory locking. Stevens & Rago (2005) observed that the <code>ed</code> editor indeed did that.<ref>{{cite book |first1=W. Richard |last1=Stevens |first2=Stephen A. |last2=Rago |date=27 June 2005 |title=Advanced Programming in the UNIX Environment |publisher=Addison-Wesley Professional |edition=Second |isbn=978-0201433074 |page=456}}</ref> Whether and how <code>flock</code> locks work on network filesystems, such as [[Network File System (protocol)|NFS]], is implementation dependent. On [[BSD]] systems, <code>flock</code> calls on a file descriptor open to a file on an NFS-mounted partition are successful [[NOP (code)|no-ops]]. On [[Linux]] prior to 2.6.12, <code>flock</code> calls on NFS files would act only locally. Kernel 2.6.12 and above implement <code>flock</code> calls on NFS files using POSIX byte-range locks. These locks will be visible to other NFS clients that implement <code>fcntl</code>-style ''POSIX locks'', but invisible to those that do not.<ref>{{cite web |url=http://nfs.sourceforge.net/ |series=Linux NFS FAQ: D |title=Commonly occurring error messages |website=nfs.sourceforge.net |publisher=Source Forge}}</ref> Lock upgrades and downgrades ''release'' the old lock before applying the new lock. If an application downgrades an exclusive lock to a shared lock while another application is blocked waiting for an exclusive lock, the latter application may get the exclusive lock and lock the first application out. This means that lock downgrades can block, which may be counter-intuitive. ''All'' <code>fcntl</code> locks associated with a file for a given process are removed when ''any'' file descriptor for that file is closed by that process, even if a lock was never requested for that file descriptor. Also, <code>fcntl</code> locks are not inherited by a child process. The <code>fcntl</code> close semantics are particularly troublesome for applications that call subroutine libraries that may access files. Neither of these "bugs" occurs using real <code>flock</code>-style locks. Preservation of the lock status on open file descriptors passed to another process using a [[Unix domain socket]] is implementation dependent.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)