IT lexicon › Infra & Ops › File locking

File locking

Infra & Ops På svenska → Updated: 2026-11-17

Mechanisms to prevent multiple processes from writing the same file simultaneously, using either advisory locks (flock) or record locks (fcntl).

File locking prevents race conditions when multiple processes access the same file. flock() (BSD-style) locks the entire file; fcntl() locks specific byte ranges. Both are advisory—they are enforced only if processes cooperate. Mandatory locks (rarely seen) are enforced by the kernel regardless of cooperation but are error-prone and can deadlock entire systems. NFS locking is notoriously broken; locks are not network-aware and don't survive server reboots, making distributed locking a minefield.

← Back to the lexicon