1.\" $NetBSD: pty.4,v 1.9 2002/02/02 07:35:49 tls Exp $ 2.\" 3.\" Copyright (c) 1983, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)pty.4 8.2 (Berkeley) 11/30/93 35.\" 36.Dd November 30, 1993 37.Dt PTY 4 38.Os 39.Sh NAME 40.Nm pty 41.Nd pseudo terminal driver 42.Sh SYNOPSIS 43.Cd pseudo-device pty Op Ar count 44.Sh DESCRIPTION 45The 46.Nm 47driver provides support for a device-pair termed a 48.Em pseudo terminal . 49A pseudo terminal is a pair of character devices, a 50.Em master 51device and a 52.Em slave 53device. 54The slave device provides to a process an interface identical to 55that described in 56.Xr tty 4 . 57However, whereas all other devices which provide the interface described in 58.Xr tty 4 59have a hardware device of some sort behind them, the slave device 60has, instead, another process manipulating it through the master 61half of the pseudo terminal. 62That is, anything written on the master device is given to the 63slave device as input and anything written on the slave device is 64presented as input on the master device. 65.Pp 66In configuring, if an optional 67.Ar count 68is given in 69the specification, that number of pseudo terminal pairs is initially configured; 70the default count is 16. Additional pseudo terminal pairs are allocated on 71as-needed basis, maximum number of them is controlled via 72.Em kern.maxptys 73sysctl (defaults to 992). 74.Pp 75The following 76.Xr ioctl 2 77calls apply only to pseudo terminals: 78.Bl -tag -width TIOCREMOTE 79.It Dv TIOCSTOP 80Stops output to a terminal (e.g. like typing 81.Ql ^S ) . 82Takes 83no parameter. 84.It Dv TIOCSTART 85Restarts output (stopped by 86.Dv TIOCSTOP 87or by typing 88.Ql ^S ) . 89Takes no parameter. 90.It Dv TIOCPKT 91Enable/disable 92.Em packet 93mode. 94Packet mode is enabled by specifying (by reference) a nonzero 95parameter and disabled by specifying (by reference) a zero parameter. 96When applied to the master side of a pseudo 97terminal, 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 status information. 104In the latter case, the byte is an inclusive-or 105of 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 2 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 2 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 2 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 2 193from the master side. 194The 195.Xr ioctl 2 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 2 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 to be flow controlled 209and not input edited (regardless of the terminal mode). 210Each write to the control terminal produces a record boundary for 211the process reading 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-zP-T][0-9a-zA-Z]x -compact 222.It Pa /dev/pty[p-zP-T][0-9a-zA-Z] 223master pseudo terminals 224.It Pa /dev/tty[p-zP-T][0-9a-zA-Z] 225slave pseudo terminals 226.El 227.Sh DIAGNOSTICS 228None. 229.Sh HISTORY 230The 231.Nm 232driver appeared in 233.Bx 4.2 . 234