1.\" $NetBSD: pty.4,v 1.7 1999/03/16 01:19:17 garbled 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 are configured; 70the default count is 32. 71.Pp 72The following 73.Xr ioctl 2 74calls apply only to pseudo terminals: 75.Bl -tag -width TIOCREMOTE 76.It Dv TIOCSTOP 77Stops output to a terminal (e.g. like typing 78.Ql ^S ) . 79Takes 80no parameter. 81.It Dv TIOCSTART 82Restarts output (stopped by 83.Dv TIOCSTOP 84or by typing 85.Ql ^S ) . 86Takes no parameter. 87.It Dv TIOCPKT 88Enable/disable 89.Em packet 90mode. 91Packet mode is enabled by specifying (by reference) a nonzero 92parameter and disabled by specifying (by reference) a zero parameter. 93When applied to the master side of a pseudo 94terminal, each subsequent 95.Xr read 2 96from the terminal will return data written on the slave part of 97the pseudo terminal preceded by a zero byte (symbolically 98defined as 99.Dv TIOCPKT_DATA ) , 100or a single byte reflecting control status information. 101In the latter case, the byte is an inclusive-or 102of zero or more of the bits: 103.Bl -tag -width TIOCPKT_FLUSHWRITE 104.It Dv TIOCPKT_FLUSHREAD 105whenever the read queue for the terminal is flushed. 106.It Dv TIOCPKT_FLUSHWRITE 107whenever the write queue for the terminal is flushed. 108.It Dv TIOCPKT_STOP 109whenever output to the terminal is stopped a la 110.Ql ^S . 111.It Dv TIOCPKT_START 112whenever output to the terminal is restarted. 113.It Dv TIOCPKT_DOSTOP 114whenever 115.Em t_stopc 116is 117.Ql ^S 118and 119.Em t_startc 120is 121.Ql ^Q . 122.It Dv TIOCPKT_NOSTOP 123whenever the start and stop characters are not 124.Ql ^S/^Q . 125.Pp 126While this mode is in use, the presence of control status information 127to be read from the master side may be detected by a 128.Xr select 2 129for exceptional conditions. 130.Pp 131This mode is used by 132.Xr rlogin 1 133and 134.Xr rlogind 8 135to implement a remote-echoed, locally 136.Ql ^S/^Q 137flow-controlled 138remote login with proper back-flushing of output; it can be 139used by other similar programs. 140.It Dv TIOCPKT_IOCTL 141When this bit is set, the slave has changed the 142.Xr termios 4 143structure (TTY state), and the remainder of the data read from 144the master side of the 145.Nm 146is a copy of the new 147.Xr termios 4 148structure. 149.Pp 150This is used by 151.Xr telnetd 8 152to implement TELNET "line mode" - it allows the 153.Xr telnetd 8 154to detect 155.Xr tty 4 156state changes by the slave, and negotiate the appropriate TELNET 157protocol equivalents with the remote peer. 158.El 159.It Dv TIOCUCNTL 160Enable/disable a mode that allows a small number of simple user 161.Xr ioctl 2 162commands to be passed through the pseudo-terminal, 163using a protocol similar to that of 164.Dv TIOCPKT . 165The 166.Dv TIOCUCNTL 167and 168.Dv TIOCPKT 169modes are mutually exclusive. 170This mode is enabled from the master side of a pseudo terminal 171by specifying (by reference) 172a nonzero parameter and disabled by specifying (by reference) 173a zero parameter. 174Each subsequent 175.Xr read 2 176from the master side will return data written on the slave part of 177the pseudo terminal preceded by a zero byte, 178or a single byte reflecting a user control operation on the slave side. 179A user control command consists of a special 180.Xr ioctl 2 181operation with no data; the command is given as 182.Dv UIOCCMD Ns (n) , 183where 184.Ar n 185is a number in the range 1-255. 186The operation value 187.Ar n 188will be received as a single byte on the next 189.Xr read 2 190from the master side. 191The 192.Xr ioctl 2 193.Dv UIOCCMD Ns (0) 194is a no-op that may be used to probe for 195the existence of this facility. 196As with 197.Dv TIOCPKT 198mode, command operations may be detected with a 199.Xr select 2 200for exceptional conditions. 201.It Dv TIOCREMOTE 202A mode for the master half of a pseudo terminal, independent 203of 204.Dv TIOCPKT . 205This mode causes input to the pseudo terminal to be flow controlled 206and not input edited (regardless of the terminal mode). 207Each write to the control terminal produces a record boundary for 208the process reading the terminal. 209In normal usage, a write of data is like the data typed as a line 210on the terminal; a write of 0 bytes is like typing an end-of-file 211character. 212.Dv TIOCREMOTE 213can be used when doing remote line 214editing in a window manager, or whenever flow controlled input 215is required. 216.El 217.Sh FILES 218.Bl -tag -width /dev/tty[p-r][0-9a-f]x -compact 219.It Pa /dev/pty[p-r][0-9a-f] 220master pseudo terminals 221.It Pa /dev/tty[p-r][0-9a-f] 222slave pseudo terminals 223.El 224.Sh DIAGNOSTICS 225None. 226.Sh HISTORY 227The 228.Nm 229driver appeared in 230.Bx 4.2 . 231