flock · shipping · also flock(2), BSD whole-file lock

flock

flock is a whole-file locking interface that associates shared or exclusive locks with an open file description on Linux.

LOCK_SH requests a shared lock, LOCK_EX an exclusive lock and LOCK_UN release; LOCK_NB requests a nonblocking attempt. Descriptors inherited through fork or created by dup share ownership. A separate open is a separate contender, even in the same process. [1]

This syscall is distinct from struct flock, the argument structure used by fcntl record-lock operations, and from the byte-range F_OFD_* API. [2]

The local Linux flock and fcntl families are separate; two programs choosing different families can both acquire locks on the same file. Network-filesystem emulation can change that relationship. [5] [1]

Hesela's local ext4 probe ran nine ordered API pairs at two compiler optimization levels with three repeats each. A flock holder admitted both fcntl contenders; the fcntl families excluded one another. All 54 fresh-child post-unlock controls succeeded. This checks one Linux 6.8.0-149-generic configuration, not network locking or durability. [7]

Relations

related
Advisory file lock, Open-file-description lock, Process-associated record lock, Open file description

Limitations

  • A failed nonblocking conversion need not preserve the earlier lock; flock has no deadlock detection. [1]
  • NFS local_lock settings can restrict exclusion to one client; a successful local lock is not cross-client coordination. [3]
  • SMB lock enforcement depends on protocol, server and mount settings; nobrl disables server byte-range lock requests. [4]
  • This record summarizes APIs, not a new network-filesystem or crash experiment. [6]

Citations

  1. Linux man-pages: flock(2), ownership, conversion and filesystem differences (accessed 2026-11-14)
  2. Linux man-pages: fcntl_locking(2), process and open-description record locks (accessed 2026-11-14)
  3. nfs(5): local_lock and client-local exclusion (accessed 2026-11-14)
  4. mount.cifs(8): nobrl and server byte-range lock requests (accessed 2026-11-14)
  5. Linux kernel: File Locking Release Notes, separate flock and fcntl families (accessed 2026-11-14)
  6. Hesela: lock families, ownership and filesystem scope (accessed 2026-11-14)
  7. Hesela: local interprocess lock-family matrix, raw observations and source hashes (accessed 2026-11-14)

JSON: /data/terms/flock.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. flock. Hesela. 2026-11-14. https://hesela.dev/terms/flock/