$linuxjunkies
>

lockfile

also: lock file, pidfile (related concept)

A file created by a program to indicate that a resource is in use, preventing other processes from accessing or modifying it simultaneously. Lockfiles prevent race conditions and ensure data integrity when multiple processes interact with the same resource.

A lockfile is an empty or minimally-populated file whose presence signals that a resource is locked. When a process needs exclusive access to something—a configuration file, a mailbox, a device—it creates a lockfile. Other processes check for the lockfile's existence before proceeding; if it exists, they wait or abort rather than proceeding, avoiding conflicts.

Common lockfile locations follow conventions like /var/run/ or /tmp/. For example, when an email client accesses your mailbox, it may create /var/spool/mail/username.lock to prevent other clients from reading or writing simultaneously.

Lockfiles must be cleaned up when the process finishes. If a process crashes without removing its lockfile, the lock may persist indefinitely—this is called a stale lockfile, and system administrators must manually delete it to unlock the resource.

Related terms