8 DESCRIPTION
9 The pseudo-tty subsystem simulates a terminal connection, where the
10 master side represents the terminal and the slave represents the user
11 process's special device end point. In order to use the pseudo-tty
12 subsystem, a node for the master side driver /dev/ptmx and N nodes for
13 the slave driver (N is determined at installation time) must be
14 installed. The names of the slave devices are /dev/pts/M where M has
15 the values 0 through N-1. When the master device is opened, the
16 corresponding slave device is automatically locked out. No user may
17 open that slave device until its permissions are adjusted and the
18 device unlocked by calling functions grantpt(3C) and unlockpt(3C). The
19 user can then invoke the open system call with the name that is
20 returned by the ptsname(3C) function. See the example below.
21
22
23 Only one open is allowed on a master device. Multiple opens are allowed
24 on the slave device. After both the master and slave have been opened,
25 the user has two file descriptors which are end points of a full duplex
26 connection composed of two streams automatically connected at the
27 master and slave drivers. The user may then push modules onto either
28 side of the stream pair. The user needs to push the ptem(7M) and
29 ldterm(7M) modules onto the slave side of the pseudo-terminal subsystem
30 to get terminal semantics.
31
32
33 The master and slave drivers pass all messages to their adjacent
34 queues. Only the M_FLUSH needs some processing. Because the read queue
35 of one side is connected to the write queue of the other, the FLUSHR
36 flag is changed to the FLUSHW flag and vice versa. When the master
37 device is closed an M_HANGUP message is sent to the slave device which
38 will render the device unusable. The process on the slave side gets the
39 errno EIO when attempting to write on that stream but it will be able
40 to read any data remaining on the stream head read queue. When all the
41 data has been read, read returns 0 indicating that the stream can no
42 longer be used. On the last close of the slave device, a 0-length
43 message is sent to the master device. When the application on the
44 master side issues a read() or getmsg() and 0 is returned, the user of
45 the master device decides whether to issue a close() that dismantles
46 the pseudo-terminal subsystem. If the master device is not closed, the
47 pseudo-tty subsystem will be available to another user to open the
48 slave device. Since 0-length messages are used to indicate that the
49 process on the slave side has closed and should be interpreted that way
50 by the process on the master side, applications on the slave side
51 should not write 0-length messages. If that occurs, the write returns
52 0, and the 0-length message is discarded by the ptem module.
53
54
55 The standard STREAMS system calls can access the pseudo-tty devices.
56 The slave devices support the O_NDELAY and O_NONBLOCK flags.
57
58 EXAMPLES
59 int fdm fds;
60 char *slavename;
61 extern char *ptsname();
62
63 fdm = open("/dev/ptmx", O_RDWR); /* open master */
64 grantpt(fdm); /* change permission of slave */
65 unlockpt(fdm); /* unlock slave */
66 slavename = ptsname(fdm); /* get name of slave */
67 fds = open(slavename, O_RDWR); /* open slave */
68 ioctl(fds, I_PUSH, "ptem"); /* push ptem */
69 ioctl(fds, I_PUSH, "ldterm"); /* push ldterm*/
70
71
72 FILES
73 /dev/ptmx
74 master clone device
75
76
77 /dev/pts/M
78 slave devices (M = 0 -> N-1)
79
80
81 SEE ALSO
82 grantpt(3C), ptsname(3C), unlockpt(3C), ldterm(7M), ptm(7D), ptem(7M)
83
84
85 STREAMS Programming Guide
86
87
88
89 August 21, 1992 PTS(7D)
|
8 DESCRIPTION
9 The pseudo-tty subsystem simulates a terminal connection, where the
10 master side represents the terminal and the slave represents the user
11 process's special device end point. In order to use the pseudo-tty
12 subsystem, a node for the master side driver /dev/ptmx and N nodes for
13 the slave driver (N is determined at installation time) must be
14 installed. The names of the slave devices are /dev/pts/M where M has
15 the values 0 through N-1. When the master device is opened, the
16 corresponding slave device is automatically locked out. No user may
17 open that slave device until its permissions are adjusted and the
18 device unlocked by calling functions grantpt(3C) and unlockpt(3C). The
19 user can then invoke the open system call with the name that is
20 returned by the ptsname(3C) function. See the example below.
21
22
23 Only one open is allowed on a master device. Multiple opens are allowed
24 on the slave device. After both the master and slave have been opened,
25 the user has two file descriptors which are end points of a full duplex
26 connection composed of two streams automatically connected at the
27 master and slave drivers. The user may then push modules onto either
28 side of the stream pair. Unless compiled in strict XPG4v2 mode (see
29 below), the consumer needs to push the ptem(7M) and ldterm(7M) modules
30 onto the slave side of the pseudo-terminal subsystem to get terminal
31 semantics.
32
33
34 The master and slave drivers pass all messages to their adjacent
35 queues. Only the M_FLUSH needs some processing. Because the read queue
36 of one side is connected to the write queue of the other, the FLUSHR
37 flag is changed to the FLUSHW flag and vice versa. When the master
38 device is closed an M_HANGUP message is sent to the slave device which
39 will render the device unusable. The process on the slave side gets the
40 errno EIO when attempting to write on that stream but it will be able
41 to read any data remaining on the stream head read queue. When all the
42 data has been read, read returns 0 indicating that the stream can no
43 longer be used. On the last close of the slave device, a 0-length
44 message is sent to the master device. When the application on the
45 master side issues a read() or getmsg() and 0 is returned, the user of
46 the master device decides whether to issue a close() that dismantles
47 the pseudo-terminal subsystem. If the master device is not closed, the
48 pseudo-tty subsystem will be available to another user to open the
49 slave device. Since 0-length messages are used to indicate that the
50 process on the slave side has closed and should be interpreted that way
51 by the process on the master side, applications on the slave side
52 should not write 0-length messages. Unless the application is compiled
53 in strict XPG4v2 mode (see below) then any 0-length messages written on
54 the slave side will be discarded by the ptem module.
55
56
57 The standard STREAMS system calls can access the pseudo-tty devices.
58 The slave devices support the O_NDELAY and O_NONBLOCK flags.
59
60 STRICT XPG4v2 MODE
61 XPG4v2 requires that open of a slave pseudo terminal device provides
62 the process with an interface that is identical to the terminal
63 interface (without having to explicitly push any modules to achieve
64 this). It also requires that 0-length messages written on the slave
65 side will be propagated to the master.
66
67 Experience has shown, however, that most software does not expect slave
68 pty devices to operate in this manner and therefore this
69 XPG4v2-compliant behaviour is disabled in illumos by default.
70
71 To enable it for an application, the _XPG4_2 and _STRICT_SYMBOLS macros
72 must be set during compilation and the application must be linked with
73 values-xpg4.o or values-xp6.o.
74
75 EXAMPLES
76 int fdm fds;
77 char *slavename;
78 extern char *ptsname();
79
80 fdm = open("/dev/ptmx", O_RDWR); /* open master */
81 grantpt(fdm); /* change permission of slave */
82 unlockpt(fdm); /* unlock slave */
83 slavename = ptsname(fdm); /* get name of slave */
84 fds = open(slavename, O_RDWR); /* open slave */
85 ioctl(fds, I_PUSH, "ptem"); /* push ptem */
86 ioctl(fds, I_PUSH, "ldterm"); /* push ldterm*/
87
88
89 FILES
90 /dev/ptmx
91 master clone device
92
93
94 /dev/pts/M
95 slave devices (M = 0 -> N-1)
96
97
98 SEE ALSO
99 grantpt(3C), ptsname(3C), unlockpt(3C), ldterm(7M), ptm(7D), ptem(7M),
100 standards(5)
101
102
103 STREAMS Programming Guide
104
105
106
107 February 29, 2020 PTS(7D)
|