Domanda

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

They are certainly not physical files. They must be some sort of temporary storage arrangement made by OS in the RAM for every process.

Are these array data structures attached to every process separately?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top