Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88783
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Nobody <nobody@nowhere.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: Help with pipes, buffering and pseudoterminals |
| Date | Fri, 10 Apr 2015 15:18:32 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 48 |
| Message-ID | <pan.2015.04.10.14.18.32.282000@nowhere.invalid> (permalink) |
| References | <c9c407e4-4914-4f5d-8ff3-ae1ac083cb82@googlegroups.com> <20150406001109.GA1009@cskk.homeip.net> <mailman.76.1428380025.12925.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | mx02.eternal-september.org; posting-host="152d4dee6f95183c956ee6fa63d7e69f"; logging-data="24877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8aH3DA0A+gZfHpl0qD0tF" |
| User-Agent | Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) |
| Cancel-Lock | sha1:uAXSCdR6WQ3pdn0gbJvZH8lmnh0= |
| Xref | csiph.com comp.lang.python:88783 |
Show key headers only | View raw
On Mon, 06 Apr 2015 21:13:41 -0700, Daniel Ellis wrote: > As for the question ptys and C, no, I have no experience in that area. > I've read a bit on the master/slave stuff, but I'm still finding it > confusing. The manpage for pty states that it creates a "pair" of virtual > devices, one master and one slave. It doesn't seem like these are simple > file descriptors for stdin, stdout, and stderr, given that there is only > one for the master and one for the slave, so I'm really not understanding > what it means for these devices to be created. A pseudo-tty (pty) is a pair of devices: master and slave. Opening either of these devices will return a file descriptor. The devices can be (and usually are) opened read-write (O_RDWR), yielding a descriptor which can be both read and written to (unlike a pipe). Typical usage is that the parent process opens the master device while the child process opens the slave device and dup2()s the descriptor to descriptors 0,1,2 (the child process is typically the leader of a new session, meaning that the slave will become its controlling terminal). The child then exec()s some program. Whatever data the parent writes to the master, the child will receive when it reads from the slave, and vice versa. So the pair of devices collectively behave somewhat like a socket pair or a bidirectional pipe. Except that the slave side "looks like" a tty, i.e. isatty() will return 1, tcsetattr() etc will work on it, input characters (sent from master to slave) will be processed (backspace, Ctrl-C, Ctrl-Z, etc), and so on. The main use for a pseudo-tty is for emulating a terminal, where the emulation is either a GUI program (xterm etc) or a network connection (telnet, ssh, etc). Using it to change the default buffering of stdin/stdout/stdout stderr is something of a hack (and a rather complex one), but it works. There are two distinct mechanisms for implementing pseudo-ttys. The BSD way is to have static device nodes for both master and slave devices. The program attempts to open the master devices /dev/pty[p-za-z][0-9a-f] in order (i.e. /dev/ptyp0 is first) until one succeeds. The corresponding slave device has the same name but with "tty" instead of "pty". The SysV way is to open /dev/ptmx. The returned descriptor is for a new master device. The slave is dynamically created within the /dev/pts pseudo-filesystem; its name can be obtained by using the ptsname() function. The Python pty module should take care of this for you.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Help with pipes, buffering and pseudoterminals Daniel Ellis <ellisd23@gmail.com> - 2015-04-05 12:20 -0700
Re: Help with pipes, buffering and pseudoterminals Nobody <nobody@nowhere.invalid> - 2015-04-06 01:06 +0100
Re: Help with pipes, buffering and pseudoterminals Cameron Simpson <cs@zip.com.au> - 2015-04-06 10:11 +1000
Re: Help with pipes, buffering and pseudoterminals Daniel Ellis <ellisd23@gmail.com> - 2015-04-06 21:13 -0700
Re: Help with pipes, buffering and pseudoterminals Nobody <nobody@nowhere.invalid> - 2015-04-10 15:18 +0100
csiph-web