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


Groups > comp.lang.python > #88620

Re: Help with pipes, buffering and pseudoterminals

References <CAPTjJmoQQ_4-hONHyEw9QTj-UbMN8yJpMOkEfRwFvAZeyiX8Aw@mail.gmail.com> <20150407220655.GA71015@cskk.homeip.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-04-07 16:28 -0600
Subject Re: Help with pipes, buffering and pseudoterminals
Newsgroups comp.lang.python
Message-ID <mailman.119.1428445767.12925.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Apr 7, 2015 at 4:06 PM, Cameron Simpson <cs@zip.com.au> wrote:
> 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.

sys.stdin and sys.stdout are distinct, uni-directional io objects. At
a lower level though, the only thing stopping you from calling
os.write on fd 0 or os.read on fd 1 or 2 is convention.

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


Thread

Re: Help with pipes, buffering and pseudoterminals Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-07 16:28 -0600

csiph-web