What are file descriptors in Linux?

Answer

A file descriptor (FD) is a non-negative integer that uniquely identifies an open file (or socket, pipe, device) within a process. The OS kernel maintains a file descriptor table per process. FD 0 = stdin, FD 1 = stdout, FD 2 = stderr. Additional FDs are allocated starting from 3. In shell scripts, you can open custom FDs: exec 3> output.txt opens FD 3 for writing; echo "data" >&3 writes to it; exec 3>&- closes it. View a process's open FDs: ls -la /proc/PID/fd/. The limit of open FDs per process is controlled by ulimit -n (default 1024; commonly raised to 65535+ for high-performance servers).