abc def
abc def

Reputation: 221

Does every process have its own stdin, stdout and stderr?

Does every process have its own stdin, stdout and stderr or do they just share 1 stdin, 1 stdout and 1 stderr? I mean of course there's generally 1 keyboard and 1 terminal for each computer, but are processes' input & output streams separated form one another?

Upvotes: 22

Views: 4158

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726929

stdout, stdin, and stderr are just the abstractions given to the process by the operating environment to interact with its inputs and outputs. Despite the fact that there is only one keyboard (in most cases, anyway) the operating system knows how to decide which process gets the current input, and delivers the keystrokes to the stdin of that process. Similarly, despite there being only one screen, it may be partitioned into several windows. Finally, many processes have their input and output tied to a file stream. Operating systems can let you bind multiple processes to a single input or to a single output file, but even in that case the objects representing stdin and stdout streams inside the process will be separate: they would reference the same object in the operating system, and the OS will manage sharing that object among its users.

Upvotes: 25

Related Questions