Serial lines were first used for connecting terminals to computers. As time went on, however, many other devices have been connected via serial lines as well: modems, printers, digital cameras, and MP3 players, to name just a few. While serial lines are not fast communications channels, they do provide a straightforward, standardized way of sending data to or from a computer. In traditional contexts, serial lines use the RS-232 communications standard. We will consider this standard in some detail later in this chapter, after we've discussed some more practical aspects of administering serial lines and devices.
12.1.1 Device Files for Serial Lines
The special files for serial ports vary between systems, but they traditionally have names of the form /dev/ttyn, where n is a one- or two-digit number corresponding to the serial line number (System V and BSD style, respectively); numbering begins at 0 or 00. For example, /dev/tty2 and /dev/tty16 correspond to the third and seventeenth serial lines on a system, respectively (BSD-style systems always use two digits: /dev/tty02). Terminals, modems, and other serial devices are accessed via these special files.
On more recent System V-based systems, special files for direct terminal lines are stored in the directory /dev/term and have names that are their line number: /dev/term/14, for example. There are often links to the older names.
The file /dev/tty (no suffix) serves a special purpose. It is a synonym for each process's controlling TTY. It can be used to ensure output goes to the terminal, regardless of any I/O redirection.
The special file /dev/console always refers to the system console device. On many workstation systems, /dev/console is redefined depending on how the workstation is being used. /dev/console refers to the system CRT display when the system is being used in a nongraphical mode. When a windowing session is running, however, /dev/console may become one of its windows (rather than the device as a whole).
Systems may have other terminal special files corresponding to devices that they support. For example, under AIX, the special file /dev/lft is used for the physical workstation console. It comes into play most often when the console is used as an ordinary character terminal (i.e., its nongraphical, command-line login mode). It is also the device to which the X server attaches when the workstation is running in its normal graphical mode.
There are also other terminal devices in /dev used for indirect login sessions via a network or windowing system; these are the pseudo-terminal devices. Each pseudo-terminal consists of two parts:
n is usually a single hexadecimal digit in both cases. The slave pseudo-terminals provide a TTY-like interface to user processes. The two parts work in pairs, with the same device number n. Output appears in the virtual terminal, and this device is also what is listed by commands like ps. On recent System V-based systems, only a single master pseudo-terminal is used for all of the virtual terminals (true for the System V names under AIX, HP-UX and Solaris; Tru64 has merged the control functionality into the slave device, thus eliminating use of a master pseudo-terminal special file).
Table 12-1 lists the special files for serial lines and pseudo-terminals on the various systems we are considering. The special files for the first serial line and the first pseudo-terminal are listed in each case.
As the table indicates, dial-out modems sometimes use a different special file than terminals do. For example, under Solaris, the special file /dev/cua/0 refers to the first serial line in dial-out mode. Similarly, under HP-UX, /dev/cua0p0 and /dev/ttyd0p0 both refer to the same serial line and are used for dial-out and dial-in modems, respectively.
The two special files differ only in their minor device numbers (their subtype within their device class), which are offset by 128. You can use the ls -l command to find the major and minor device numbers for a special file; they appear in the size field:
crw-rw-rw- 1 bin bin 1 0x000201 Feb 1 06:59 cua0p2 crw-rw-rw- 1 bin bin 1 0x000201 Feb 1 06:59 cul0p2 crw--w--w- 1 bin bin 1 0x000200 Jan 15 15:52 tty0p2 crw--w---- 1 uucp bin 1 0x000202 Feb 1 06:59 ttyd0p2
These four devices all refer to the same physical serial port, accessed in different modes: as a dial-out modem, as a direct serial connection to another computer, as a terminal line, and as a dial-in modem.
You could use the MAKEDEV or mknod command if you needed to create any of these special files for a serial line. The first is preferred if it is available because it is much easier to use:
# cd /dev # ./MAKEDEV tty4
This command will create all the special files associated with the fifth serial line.
On systems without MAKEDEV, you must run the mknod command. For example, the following commands may be used to create the additional outgoing special files for a bidirectional modem on the fifth terminal line (which is usually named /dev/tty0p4):
# mknod /dev/cul0p4 c 1 0x401 # mknod /dev/cua0p4 c 1 0x401
These commands both create character special files (the c code letter) for device class 1 (serial lines). You can then use these device files for configuring the serial line in the various contexts (as we'll see). Alternatively, you can use SAM to create any required special files, via its Peripheral Devices Terminals and Modems Actions Add Terminal or Add Modem menu path.
12.1.2 The tty Command
The tty command displays what special file is being used for a login session. For example:
$ hostname hamlet $ tty /dev/tty12 $ rlogin duncan AIX Version 5 (C) Copyrights by IBM and by others 1982, 2000. $ tty /dev/pts/4
This user is directly logged in to the 13th terminal line on hamlet. On duncan, his remote session is using pseudo-terminal 4.