Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #88619 > unrolled thread

Re: Help with pipes, buffering and pseudoterminals

Started byCameron Simpson <cs@zip.com.au>
First post2015-04-08 08:06 +1000
Last post2015-04-08 08:06 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Help with pipes, buffering and pseudoterminals Cameron Simpson <cs@zip.com.au> - 2015-04-08 08:06 +1000

#88619 — Re: Help with pipes, buffering and pseudoterminals

FromCameron Simpson <cs@zip.com.au>
Date2015-04-08 08:06 +1000
SubjectRe: Help with pipes, buffering and pseudoterminals
Message-ID<mailman.118.1428444421.12925.python-list@python.org>
On 07Apr2015 20:38, Chris Angelico <rosuav@gmail.com> wrote:
>On Tue, Apr 7, 2015 at 3:48 PM, Cameron Simpson <cs@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?

No. Have a look with lsof:

  lsof -p $$

in a terminal.

>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!

The setup is very simple: open the tty for read/write, close everything else, 
dup the tty to fds 0, 1 and 2, make the tty the child's controlling terminal.  
There's a little housekeeping like setting tty modes (erase and kill 
characters, so forth) and putting the child in its own process group, but the 
basics are as stated.

Cheers,
Cameron Simpson <cs@zip.com.au>

TeX: When you pronounce it correctly to your computer, the terminal may
     become slightly moist.     - D. E. Knuth.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web