{
  "slug": "file-descriptor",
  "term": "File descriptor",
  "aliases": [
    "file descriptor number"
  ],
  "definition": "A file descriptor is a nonnegative integer used by a process to refer to an open file description for operations such as reading, writing or closing.",
  "note": "A descriptor number is a process-local reference, not a persistent identifier for a pathname or inode. Separate opens can create different open file descriptions for the same file; dup creates another reference to the existing description. [linux-open] [linux-dup]\n\nDuplicated descriptors share the file offset and status flags, but not descriptor flags such as close-on-exec. Closing one alias does not close the other. After release, the same number can identify a different file, so a saved integer alone does not prove ownership of the current descriptor. [linux-dup] [posix-close]\n\nOn Linux, a successful dup2 with distinct source and target numbers replaces the target atomically; separate close then dup leaves an allocation race. Successful replacement clears the target FD_CLOEXEC flag while leaving the source descriptor flag unchanged. A valid dup2(fd, fd) instead does nothing, preserving descriptor flags. An invalid source fails without closing the target. Atomic replacement is not durable storage, and dup2 does not report implicit target-close errors. [linux-dup]\n\nRetained access: in a separate same-owner Linux 6.8 experiment on ext4 and tmpfs, chmod 000 denied fresh opens but retained read/write descriptors and a duplicate created after the change still accessed the file. Closing one descriptor did not revoke the duplicate or a surviving mapping. This is one-host visibility evidence, not crash durability, named-user ACL selection or a universal revocation rule. [lifetime-study] NFS and additional security-policy checks require separate treatment. [lifetime-chmod]",
  "status": "shipping",
  "advantages": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-05",
  "limitations": [
    "Descriptor numbers can be reused after release.",
    "Sharing a descriptor or open file description does not provide a durable-commit guarantee."
  ],
  "related": [
    "pread",
    "file-offset",
    "open-file-description",
    "close",
    "inode",
    "pwrite",
    "close-on-exec"
  ],
  "citations": [
    {
      "id": "linux-open",
      "title": "Linux man-pages 6.19: open(2), descriptors and open file descriptions",
      "url": "https://man7.org/linux/man-pages/man2/open.2.html",
      "accessed": "2026-10-17"
    },
    {
      "id": "linux-dup",
      "title": "Linux man-pages 6.19: dup(2), shared state and atomic replacement",
      "url": "https://man7.org/linux/man-pages/man2/dup.2.html",
      "accessed": "2026-10-17"
    },
    {
      "id": "posix-close",
      "title": "POSIX.1-2024: close(), descriptor deallocation",
      "url": "https://pubs.opengroup.org/onlinepubs/9799919799/functions/close.html",
      "accessed": "2026-10-17"
    },
    {
      "id": "hesela-descriptors",
      "title": "Hesela: Reproduce descriptor lifetime without injecting a storage fault",
      "url": "https://hesela.com/analyses/fsync-failure-retry-durability/#descriptor-lifetime",
      "accessed": "2026-10-17"
    },
    {
      "id": "lifetime-chmod",
      "title": "Linux man-pages: chmod(2), NFS qualification",
      "url": "https://man7.org/linux/man-pages/man2/chmod.2.html",
      "accessed": "2026-11-05"
    },
    {
      "id": "lifetime-study",
      "title": "Hesela: retained local access after permission changes, native evidence and limits",
      "url": "https://hesela.com/analyses/posix-acl-restore-permissions/#retained-access",
      "accessed": "2026-11-05"
    },
    {
      "id": "lifetime-evidence",
      "title": "Hesela: permission-lifetime native observations, source receipts and MIT replay bundle",
      "url": "https://hesela.dev/research/permission-lifetime/permission-lifetime.zip",
      "accessed": "2026-11-05"
    }
  ],
  "provenance": [
    "Permission-lifetime evidence: nine scenarios, 108 recorded executions and 108 matching replay records; two compiler configurations, three repetitions per mount and one host, not independent fleet samples. No changed LSM policy, concurrent writer or power-loss experiment. [lifetime-evidence]",
    "Inheritance: raw Linux dup clears close-on-exec on its new descriptor; dup3 with O_CLOEXEC sets it on a distinct target. Prefer creation-time O_CLOEXEC when another thread could fork and exec before a later fcntl sets FD_CLOEXEC. [linux-dup] [linux-open]"
  ]
}
