How exactly stdin, stdout, stderr are implemented in linux? How exactly stdin, stdout, stderr are implemented in linux? unix unix

How exactly stdin, stdout, stderr are implemented in linux?


stdin, stderr, and stdout are file descriptors (or FILE* wrappers around them, if you mean the C stdio objects bearing those names). File descriptors are numbers that index a per-process data structure in the kernel. That data structure records which I/O channels a process has open, I/O channel being my ad-hoc term for a file, device, socket, or pipe.

By convention, the first entry in the table has index 0 and is called the standard input, 1 is the standard output and 2 is the standard error channel. This is just a convention in Unix programs; as far as the kernel is concerned, nothing's special about these numbers.

Each I/O system call (read, write, etc.) takes a file descriptor that indicates which channel the call should operate on.