File Descriptors: The Numbers Behind Everything
File Descriptors: The Numbers Behind Everything The Integers That Run Your System Reading time: ~13 minutes You called open("config.toml") and got back the number 3. Not a file handle. Not a stream...

Source: DEV Community
File Descriptors: The Numbers Behind Everything The Integers That Run Your System Reading time: ~13 minutes You called open("config.toml") and got back the number 3. Not a file handle. Not a stream object. Not a path. A small integer. The language runtime probably wrapped it in something friendlier — a File object, a BufferedReader, an io.TextIOWrapper — but that wrapping happens after the kernel gave you a number. The number is the real thing. That number is a file descriptor, and it's the single abstraction that holds together files, sockets, pipes, terminals, timers, signals, and /dev/null. They are all just integers pointing into a kernel table. Understanding that table — and what the kernel does with it — will explain a dozen things that have probably confused you at some point. The Three That Are Already There Every Unix process starts with three file descriptors already open. stdin is 0. stdout is 1. stderr is 2. You didn't open them. They were inherited from your parent process