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


Groups > comp.lang.python > #88619

Re: Help with pipes, buffering and pseudoterminals

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'only,': 0.07; 'caller': 0.09; 'modes': 0.09; 'cc:addr:python-list': 0.11; 'subject:Help': 0.11; '>on': 0.16; 'descriptor.': 0.16; 'descriptors': 0.16; 'dup': 0.16; 'fds': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'only?': 0.16; 'open()': 0.16; 'simpson': 0.16; 'stderr': 0.16; 'stdout': 0.16; 'tty': 0.16; 'unix,': 0.16; 'wrote:': 0.18; 'else,': 0.19; 'slightly': 0.19; 'putting': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'controlling': 0.24; 'of.': 0.24; 'cheers,': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'dos': 0.30; "i'm": 0.30; 'stated.': 0.31; 'file': 0.32; 'open': 0.33; 'device': 0.34; 'maybe': 0.34; 'subject:with': 0.35; 'usual': 0.35; 'but': 0.35; 'skip:> 10': 0.36; 'charset:us-ascii': 0.36; 'operating': 0.37; 'initially': 0.38; 'massive': 0.38; 'pm,': 0.38; 'little': 0.38; 'no.': 0.61; 'content-disposition:inline': 0.62; 'group,': 0.63; 'become': 0.64; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'close': 0.67; 'believe': 0.68; 'default': 0.69; '2015': 0.84; 'characters,': 0.84; 'grew': 0.84; 'housekeeping': 0.84; 'received:192.168.15': 0.84
Date Wed, 8 Apr 2015 08:06:55 +1000
From Cameron Simpson <cs@zip.com.au>
To Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Subject Re: Help with pipes, buffering and pseudoterminals
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
In-Reply-To <CAPTjJmoQQ_4-hONHyEw9QTj-UbMN8yJpMOkEfRwFvAZeyiX8Aw@mail.gmail.com>
User-Agent Mutt/1.5.23 (2014-03-12)
References <CAPTjJmoQQ_4-hONHyEw9QTj-UbMN8yJpMOkEfRwFvAZeyiX8Aw@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.118.1428444421.12925.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1428444421 news.xs4all.nl 2883 [2001:888:2000:d::a6]:46130
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:88619

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web