{
  "slug": "flock",
  "term": "flock",
  "aliases": [
    "flock(2)",
    "BSD whole-file lock"
  ],
  "definition": "flock is a whole-file locking interface that associates shared or exclusive locks with an open file description on Linux.",
  "note": "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. [flock]\n\nThis syscall is distinct from struct flock, the argument structure used by fcntl record-lock operations, and from the byte-range F_OFD_* API. [fcntl]\n\nThe 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. [linux-lock-families] [flock]\n\nHesela'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. [hesela-matrix]",
  "status": "shipping",
  "advantages": [],
  "limitations": [
    {
      "text": "A failed nonblocking conversion need not preserve the earlier lock; flock has no deadlock detection.",
      "citationIds": [
        "flock"
      ]
    },
    {
      "text": "NFS local_lock settings can restrict exclusion to one client; a successful local lock is not cross-client coordination.",
      "citationIds": [
        "nfs-lock-scope"
      ]
    },
    {
      "text": "SMB lock enforcement depends on protocol, server and mount settings; nobrl disables server byte-range lock requests.",
      "citationIds": [
        "cifs-lock-scope"
      ]
    },
    {
      "text": "This record summarizes APIs, not a new network-filesystem or crash experiment.",
      "citationIds": [
        "hesela-locks"
      ]
    }
  ],
  "related": [
    "advisory-file-lock",
    "open-file-description-lock",
    "process-associated-record-lock",
    "open-file-description"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-14",
  "citations": [
    {
      "id": "flock",
      "title": "Linux man-pages: flock(2), ownership, conversion and filesystem differences",
      "url": "https://man7.org/linux/man-pages/man2/flock.2.html",
      "accessed": "2026-11-14"
    },
    {
      "id": "fcntl",
      "title": "Linux man-pages: fcntl_locking(2), process and open-description record locks",
      "url": "https://man7.org/linux/man-pages/man2/fcntl_locking.2.html",
      "accessed": "2026-11-14"
    },
    {
      "id": "nfs-lock-scope",
      "title": "nfs(5): local_lock and client-local exclusion",
      "url": "https://man7.org/linux/man-pages/man5/nfs.5.html",
      "accessed": "2026-11-14"
    },
    {
      "id": "cifs-lock-scope",
      "title": "mount.cifs(8): nobrl and server byte-range lock requests",
      "url": "https://man7.org/linux/man-pages/man8/mount.cifs.8.html",
      "accessed": "2026-11-14"
    },
    {
      "id": "linux-lock-families",
      "title": "Linux kernel: File Locking Release Notes, separate flock and fcntl families",
      "url": "https://docs.kernel.org/filesystems/locks.html",
      "accessed": "2026-11-14"
    },
    {
      "id": "hesela-locks",
      "title": "Hesela: lock families, ownership and filesystem scope",
      "url": "https://hesela.com/analyses/atomic-rename-directory-durability/#lock-families",
      "accessed": "2026-11-14"
    },
    {
      "id": "hesela-matrix",
      "title": "Hesela: local interprocess lock-family matrix, raw observations and source hashes",
      "url": "https://hesela.dev/research/flock-compatibility/observation.json",
      "accessed": "2026-11-14"
    }
  ]
}
