stdout , stdin and stderr are just abstractions given to the process by the operating environment for interacting with its inputs and outputs. Despite the fact that in any case there is only one keyboard (in most cases), the operating system knows how to decide which process receives the current input and passes keystrokes to stdin this process. Similarly, despite having only one screen, it can be split into multiple windows. Finally, many processes have their own input and output, tied to a file stream. Operating systems can associate several processes with one input or with one output file, but even in this case, the objects representing the stdin and stdout streams inside the process will be separate: they will refer to the same object in the operating system, and the OS will control sharing this object among its users.
source share