1TTY(4) Kernel Interfaces Manual TTY(4)
2
3
4
6 tty - general terminal interface
7
9 #include <sgtty.h>
10
12 This section describes both a particular special file /dev/tty and the
13 terminal drivers used for conversational computing.
14
15 Line disciplines.
16
17 The system provides different line disciplines for controlling communi‐
18 cations lines. In this version of the system there are two disciplines
19 available for use with terminals:
20
21 old The old (Version 7) terminal driver. This is sometimes used
22 when using the standard shell sh(1).
23
24 new The standard Berkeley terminal driver, with features for job
25 control; this must be used when using csh(1).
26
27 Line discipline switching is accomplished with the TIOCSETD ioctl:
28
29 int ldisc = LDISC;
30 ioctl(f, TIOCSETD, &ldisc);
31
32 where LDISC is OTTYDISC for the standard tty driver and NTTYDISC for
33 the ``new'' driver. The standard (currently old) tty driver is disci‐
34 pline 0 by convention. Other disciplines may exist for special pur‐
35 poses, such as use of communications lines for network connections.
36 The current line discipline can be obtained with the TIOCGETD ioctl.
37 Pending input is discarded when the line discipline is changed.
38
39 All of the low-speed asynchronous communications ports can use any of
40 the available line disciplines, no matter what hardware is involved.
41 The remainder of this section discusses the “old” and “new” disci‐
42 plines.
43
44 The control terminal.
45
46 When a terminal file is opened, it causes the process to wait until a
47 connection is established. In practice, user programs seldom open
48 these files; they are opened by getty(8) or rlogind(8C) and become a
49 user's standard input and output file.
50
51 If a process which has no control terminal opens a terminal file, then
52 that terminal file becomes the control terminal for that process. The
53 control terminal is thereafter inherited by a child process during a
54 fork(2), even if the control terminal is closed.
55
56 The file /dev/tty is, in each process, a synonym for a control terminal
57 associated with that process. It is useful for programs that wish to
58 be sure of writing messages on the terminal no matter how output has
59 been redirected. It can also be used for programs that demand a file
60 name for output, when typed output is desired and it is tiresome to
61 find out which terminal is currently in use.
62
63 A process can remove the association it has with its controlling termi‐
64 nal by opening the file /dev/tty and issuing an
65
66 ioctl(f, TIOCNOTTY, 0);
67
68