{
  "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]",
  "status": "shipping",
  "advantages": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-10-17",
  "limitations": [
    "Descriptor numbers can be reused after release.",
    "Sharing a descriptor or open file description does not provide a durable-commit guarantee."
  ],
  "related": [
    "open-file-description",
    "close",
    "inode",
    "pwrite"
  ],
  "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"
    }
  ]
}
