Help with pipes, buffering and pseudoterminals

Chris Angelico rosuav at gmail.com
Tue Apr 7 06:38:00 EDT 2015


On Tue, Apr 7, 2015 at 3:48 PM, Cameron Simpson <cs at zip.com.au> wrote:
> The operating system arranges the commection of the shell to the terminal.
> Your usual program has by default a stdin, stdout and stderr. These are
> _all_ the same file handle, duplicated to each of the three file descriptors
> 0, 1 and 2 respectively. On the operating system side, the OS has performed
> _one_ open() call on the terminal device and handed the caller a single file
> descriptor. The caller then calls dup() (or modernly, dup2()) to present the
> open terminal as stdin, stdout and stderr.

Really? I can believe that stdout and stderr are initially duplicates,
but stdin as well? Isn't stdin opened for reading only, and
stdout/stderr for writing only?

I grew up on DOS and OS/2, not on Unix, so maybe there's a massive
simplification here that I'm not aware of. That'd be pretty clean and
tidy if what you say is the case!

ChrisA



More information about the Python-list mailing list