Sobes.tech
Junior — Middle

Explain what a file descriptor is in the Linux operating system

sobes.tech AI

Answer from AI

A file descriptor in Linux is an integer identifier used by the operating system to manage open files, sockets, devices, and other input/output resources.

When a process opens a file or creates a socket, the kernel returns a file descriptor — an index in the process's open file table. Through this descriptor, the process can read, write, close the resource, and perform other operations.

For example, standard input/output streams have fixed descriptors:

  • 0 — stdin
  • 1 — stdout
  • 2 — stderr

File descriptors allow abstracting the work with different types of resources in a unified way, using system calls like read(), write(), close().