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!
== Lock files == [[Shell script]]s and other programs often use a strategy similar to the use of file locking: creation of ''lock files'', which are files whose contents are irrelevant (although often one will find the [[process identifier]] of the holder of the lock in the file) and whose sole purpose is to signal by their presence that some resource is locked. A lock file is often the best approach if the resource to be controlled is not a regular file at all, so using methods for locking files does not apply. For example, a lock file might govern access to a set of related resources, such as several different files, directories, a group of disk partitions, or selected access to higher level protocols like servers or database connections. When using lock files, care must be taken to ensure that operations are [[Atomic (computer science)|atomic]]. To obtain a lock, the process must verify that the lock file does not exist and then create it, whilst preventing another process from creating it in the meantime. Various methods to do this include: * Using the <code>lockfile</code> command (a conditional semaphore-file creator distributed in the <code>procmail</code> package). * System calls that create a file, but fail if the file already exists. (System calls are available from languages such as C or C++, and shell scripts can make use of [[noclobber]]) * Using the <code>mkdir</code> command and checking the exit code for failure<ref>{{cite web|url=http://wiki.bash-hackers.org/howto/mutex|title=Lock your script (against parallel run)|archive-url=https://web.archive.org/web/20100801064353/http://wiki.bash-hackers.org/howto/mutex|archive-date=August 1, 2010|url-status=usurped}}</ref> Lock files are often named with a tilde (<code>~</code>) prefixed to the name of the file they are locking, or a duplicate of the full file name suffixed with <code>.LCK</code> . If they are locking a resource other than a file, they may be named more arbitrarily.
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)