Questions tagged [lock]

Use for questions regarding the mechanism to prevent concurrent access to shared resources by means of lock files or in-memory synchronization primitives. For the mechanism to prevent access to unattended desktop computers, use "screen-lock" instead. For questions regarding the unresponsive computer programs, use "freeze" instead.

Overview

In multi-tasking operating systems, it is often necessary to prevent concurrent access to a single resource available to multiple threads. Common cases of such resources are e.g. files or shared memory segments, where two processes writing simultaneously to the resource may corrupt each other's data, or a process reading from the resource may receive inconsistent data if another process is writing to the resource at the same time.

Examples

  • Lock file:

    A file whose presence indicates to other processes that a certain resource is in use and therefore locked. A process wanting to access the resource checks for the presence of the lock file, and if it is found, refrains from using the resource (at least until the file has disappeared). If the file is not present, the process will create the file and start using the resource.

    If the process is abnormally terminated before it can remove the files, a stale lock condition occurs in which no process is able to use the resource anymore until the file is removed by external intervention.

    Lock files may be created e.g. by using the lockfile command included in the procmail package.

  • Mutex:

    A variable or data structure indicating to other threads that a resource is locked. Many Unix-like operating systems include the pthreads library, which contains an implementation of Mutexes and other locking and synchronization devices, along with function calls to manage them.

Related tags

Further reading

Misplaced uses

This tag should not be used for

  • the mechanisms that lock the screen of desktop computers to prevent unauthorized access when the computer is unattended. Use the tag for such questions.
  • conditions in which a computer program is "locked up", i.e. unresponsive. Use either or in that case.
137 questions
2
votes
2 answers

Lock Parted Magic?

Is it possible to lock the Parted Magic screen so that others don't tamper with it while it's in the middle of long operations?
jrc03c
  • 123
0
votes
0 answers

What's the best way to lock a directory from remove & edits?

I have a few directories that I want to lock. This lock should provide the following: Disallow anyone (including myself) from removing from that directory without a password Disallow anyone (including myself) from changing existing files in that…
David
  • 163
0
votes
2 answers

How can I simulate locking a file?

I would like to lock a file, run some tests then unlock the file. How can I do this. I could use the command line, perl, or a shell script. The reason I would like to lock the file is occasionally when connecting with ftp to our Apache server we get…
Off The Gold
  • 195
  • 2
  • 8
0
votes
1 answer

How to completely close linux from outside world?

This is theoretical question that seems to be interesting (at least for me). What would you do to completely close the whole system from outside world? By close I mean that any human shouldn't be able to login and it should only do some tasks with…