xref: /openbsd-src/share/man/man4/pty.4 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: pty.4,v 1.5 2000/07/10 13:27:35 aaron Exp $
2.\"	$NetBSD: pty.4,v 1.4 1998/03/21 03:14:30 fair Exp $
3.\"
4.\" Copyright (c) 1983, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"     @(#)pty.4	8.2 (Berkeley) 11/30/93
36.\"
37.Dd November 30, 1993
38.Dt PTY 4
39.Os
40.Sh NAME
41.Nm pty
42.Nd pseudo terminal driver
43.Sh SYNOPSIS
44.Nm pseudo-device pty
45.Op Ar count
46.Sh DESCRIPTION
47The
48.Xr pty
49driver provides support for a device-pair termed a
50.Em pseudo terminal .
51A pseudo terminal is a pair of character devices, a
52.Em master
53device and a
54.Em slave
55device.
56The slave device provides to a process an interface identical to that
57described in
58.Xr tty 4 .
59However, whereas all other devices which provide the
60interface described in
61.Xr tty 4
62have a hardware device of some sort behind them, the slave
63device has, instead, another process manipulating
64it through the master half of the pseudo terminal.
65That is, anything written on the master device is
66given to the slave device as input and anything written
67on the slave device is presented as input on the master
68device.
69.Pp
70In configuring, if an optional
71.Ar count
72is given in
73the specification, that number of pseudo terminal pairs are configured;
74the default count is 32.
75.Pp
76The following
77.Xr ioctl 2
78calls apply only to pseudo terminals:
79.Bl -tag -width TIOCREMOTE
80.It Dv TIOCSTOP
81Stops output to a terminal (e.g., like typing
82.Ql ^S ) .
83Takes
84no parameter.
85.It Dv TIOCSTART
86Restarts output (stopped by
87.Dv TIOCSTOP
88or by typing
89.Ql ^S ) .
90Takes no parameter.
91.It Dv TIOCPKT
92Enable/disable
93.Em packet
94mode.
95Packet mode is enabled by specifying (by reference) a non-zero parameter
96and disabled by specifying (by reference) a zero parameter.
97When applied to the master side of a pseudo terminal, each subsequent
98.Xr read 2
99from the terminal will return data written on the slave part of
100the pseudo terminal preceded by a zero byte (symbolically
101defined as
102.Dv TIOCPKT_DATA ) ,
103or a single byte reflecting control
104status information.
105In the latter case, the byte is an inclusive-or of zero or more of the bits:
106.Bl -tag -width TIOCPKT_FLUSHWRITE
107.It Dv TIOCPKT_FLUSHREAD
108whenever the read queue for the terminal is flushed.
109.It Dv TIOCPKT_FLUSHWRITE
110whenever the write queue for the terminal is flushed.
111.It Dv TIOCPKT_STOP
112whenever output to the terminal is stopped a la
113.Ql ^S .
114.It Dv TIOCPKT_START
115whenever output to the terminal is restarted.
116.It Dv TIOCPKT_DOSTOP
117whenever
118.Em t_stopc
119is
120.Ql ^S
121and
122.Em t_startc
123is
124.Ql ^Q .
125.It Dv TIOCPKT_NOSTOP
126whenever the start and stop characters are not
127.Ql ^S/^Q .
128.Pp
129While this mode is in use, the presence of control status information
130to be read from the master side may be detected by a
131.Xr select 2
132for exceptional conditions.
133.Pp
134This mode is used by
135.Xr rlogin 1
136and
137.Xr rlogind 8
138to implement a remote-echoed, locally
139.Ql ^S/^Q
140flow-controlled
141remote login with proper back-flushing of output; it can be
142used by other similar programs.
143.It Dv TIOCPKT_IOCTL
144When this bit is set, the slave has changed the
145.Xr termios 4
146structure (TTY state), and the remainder of the data read from
147the master side of the
148.Nm
149is a copy of the new
150.Xr termios 4
151structure.
152.Pp
153This is used by
154.Xr telnetd 8
155to implement TELNET "line mode" - it allows the
156.Xr telnetd 8
157to detect
158.Xr tty 4
159state changes by the slave, and negotiate the appropriate TELNET
160protocol equivalents with the remote peer.
161.El
162.It Dv TIOCUCNTL
163Enable/disable a mode that allows a small number of simple user
164.Xr ioctl
165commands to be passed through the pseudo-terminal,
166using a protocol similar to that of
167.Dv TIOCPKT .
168The
169.Dv TIOCUCNTL
170and
171.Dv TIOCPKT
172modes are mutually exclusive.
173This mode is enabled from the master side of a pseudo terminal
174by specifying (by reference)
175a nonzero parameter and disabled by specifying (by reference)
176a zero parameter.
177Each subsequent
178.Xr read
179from the master side will return data written on the slave part of
180the pseudo terminal preceded by a zero byte,
181or a single byte reflecting a user control operation on the slave side.
182A user control command consists of a special
183.Xr ioctl
184operation with no data; the command is given as
185.Dv UIOCCMD Ns (n) ,
186where
187.Ar n
188is a number in the range 1-255.
189The operation value
190.Ar n
191will be received as a single byte on the next
192.Xr read
193from the master side.
194The
195.Xr ioctl
196.Dv UIOCCMD Ns (0)
197is a no-op that may be used to probe for
198the existence of this facility.
199As with
200.Dv TIOCPKT
201mode, command operations may be detected with a
202.Xr select
203for exceptional conditions.
204.It Dv TIOCREMOTE
205A mode for the master half of a pseudo terminal, independent
206of
207.Dv TIOCPKT .
208This mode causes input to the pseudo terminal
209to be flow controlled and not input edited (regardless of the terminal mode).
210Each write to the control terminal produces a record boundary for the process
211reading the terminal.
212In normal usage, a write of data is like the data typed as a line
213on the terminal; a write of 0 bytes is like typing an end-of-file
214character.
215.Dv TIOCREMOTE
216can be used when doing remote line
217editing in a window manager, or whenever flow controlled input
218is required.
219.El
220.Sh FILES
221.Bl -tag -width /dev/tty[p-r][0-9a-f]x -compact
222.It Pa /dev/pty[p-r][0-9a-f]
223master pseudo terminals
224.It Pa /dev/tty[p-r][0-9a-f]
225slave pseudo terminals
226.El
227.Sh SEE ALSO
228.Xr tty 4
229.Sh HISTORY
230The
231.Nm
232driver appeared in
233.Bx 4.2 .
234