Previous | Next
Objectives|
Introduction|
Hardware|
Software|
The Login Process|
Line Configuration|
Terminal Characteristics|
Conclusions|
Review Questions
Section 10
TERMINALS
By the end of this section you should
- have been introduced to procedures for connecting terminals to a UNIX computer,
- be able to describe the login procedure for a terminal,
- be able to list and explain the configuration files used by terminals,
- be able to explain the purpose of the commands tty stty,
- explain the purpose and relation between termcap and terminfo,
UNIX is a multi-user operating system. To make use of this attribute multiple users must be able to connect to the system at the same time. This implies that there must be multiple access points. Dumb terminals are the cheapest method for providing multiple access points to a UNIX machine.
In most cases a dumb terminal is connected to a UNIX machine using a serial line. A dumb terminal does little more than present text to the user and transfer keystrokes from the terminal back to the central computer. It is dumb because the terminal does no processing on the data.
Even though the interface on such beasts is primitive they are still one of the most used methods for adding extra access points to a UNIX computer. Businesses wanting to use dumb terminals have two options
- purpose built dumb terminals, or
- modern personal computers using communications programs to simulate dumb terminals.
The process of connecting terminals to a UNIX machine follows a fairly generic set of steps that can be divided into two separate sections, hardware and software. Figure 10.1 lists the steps in the hardware process.
- Choose a port on the computer.
The device has to be connected to the computer . To do so an I/O port and the associated device file must be chosen.
- Obtain the correct cable.
Find a cable of the right type that has the right plugs for your device and computer.
- Configure the device.
The device will have to be configured to work correctly with your machine.
- Make the connection.
Connect the device and prepare it for operation.
- Test the connection.
Send output of some description to the device file to test whether or not the hardware connection is working.
Figure 10.1. Generic Hardware Process for Adding a Device.
Ports and Devices
There are two steps to choosing a port to which to connect a device
- choosing the physical port, and
A typical UNIX computer is likely to have many different ports of various configurations. Some computers will be connected to multi-port cards that supply multiple (4, 20 and more) ports.
- finding the corresponding logical device file.
Each physical connector has a corresponding device file through which the operating system passes information to the port.
Table 10.1 lists some of the common device files on a UNIX machine.
Device File Purpose
/dev/ttyn Generic device file used for terminals,
usually corresponds to a serial port
(n is a number e.g. /dev/tty0)
/dev/modem modem device file
/dev/lp line printer device file
/dev/par parallel port
/dev/ser serial port
Table 10.1. Example Device Filenames.
Terminals are generally connected using serial ports. The number, type and location of the serial ports will be machine specific. Some machines will have multi-port serial cards that provide from four or more serial ports.
Most serial ports will be associated with device files of the format /dev/ttyn, where n is some number.
Cables
The next step is obtaining the correct cable to connect the device to the computer. To do so the cable must be correctly configured and have connectors that are the
- right sex, and
Plugs are either female (small holes) or male (small prongs).
- the correct size
Serial plugs for example can be either 9 pin, 25 pin or a couple of other configurations.
Even though serial cables are meant to follow the RS-232 standard there are a number of differences that mean no two serial cables are the same.
Serial cables are used to connect two different types of device
- DTE, data terminal equipment
Most terminals and computers fall into this category.
- DCE, data communications equipment
Modems and serial printers fall into this category.
The type of serial cable you use depends on the type of equipment you are connecting. Table 10.2 explains.
Connection Cable Type
DTE <-> DCE straight modem cable
DTE <-> DTE null modem cable
Table 10.2. Types of Serial Cable.
Reading.
UNIX System Administration Handbook (2nd Ed.) Chapter 8.
Purpose.
An optional reading that explains in more detail the ins and outs of RS-232 cables. This section will not be examined and is simply included for reference.
Terminal Configuration
For a dumb terminal to work correctly it must be configured properly. Characteristics of a dumb terminal that need to be configured include
- bits per second,
The speed at which information can be transferred. Typical values (for today) range from 9600 bps up to 38,400 bps.
- parity,
Typically be set off.
- duplex,
This should be set to full and signifies that data can be transferred in both directions simultaneously.
- auto linefeed,
Should be turned off. The end of a line under UNIX is signified by a newline character. MS-DOS and other systems use a combination of a newline and a carriage return character.
- data bits, and
Suggested values are either 7 or 8 with 7 being the preference.
- stop bits.
With 7 data bits use 2 stop bits. With 8 data bits use 1 stop bit.
In the case of purpose built dumb terminals, configuration will generally be performed by setting dip switches. In the case of a personal computer and a communications package these settings are set using the options within the communications program.
Testing the Connection
Once all the hardware is configured, connected, and turned on, the next step is to test whether or not you can actually transmit data through the connection. The simplest method to do this is to send some information directly to the device file associated with the device.
For example:
ls -l / > /dev/tty1
If the connection is correct and working you should see the output
appear on the device.
Be careful when you are choosing device files to send output to.
Sending output to the wrong device can be disastrous.
For example, one of the previous students for this subject tried the command ls > /dev/hda on a Linux box. Under Linux /dev/hda is the device file for the first hard disk. Since he was the root user at the time the operating system happily sent the data to the hard disk.
By writing directly to the device file he bypassed the file system code that places the data on the drive into the correct format. As a result the data on the disk was lost.
Reasons Why It Won't Work
There are a number or reasons why a connection may not work including
- incorrect permissions,
For the test to work you must have write permission on the device file. Check the permissions. Typically you have to be the root user to perform the test. Don't change the permissions on the device file to something like world write. This can be a security hole.
- the wrong device file,
You've picked the wrong device file and the information isn't being sent to the new device.
- incorrect configuration, and
The hardware configuration on the device is not correct. Don't expect the output you send to the device to appear picture perfect. Since you are bypassing the normal mechanism for using the device it may not work 100%.
- incorrect cabling.
Is the device turned on? Are you sure you have the correct type of cable.
Exercise 10.1. Beg, borrow or steal a dumb terminal (another PC with a communications program will suffice). Perform all the steps listed above for connecting the terminal to your UNIX machine.
Terminal configuration files is one area in which the diversity of UNIX platforms rears its ugly head. System V based machines will use different configuration files than BSD based systems. Early BSD systems use different configuration files again.
Terminal configuration files can be divided along the lines of their purpose
- enabling the login process,
For a terminal to work users have to login. For users to login particular processes have to be executed for each terminal. There are configuration files that control which device files have the login process enabled.
- setting line configuration, and
The operating system has to know about and set the characteristics of the serial line that the terminal is connected to, speed, data bits, parity etc.
- terminal characteristics.
Different terminals have different keyboard layouts, different capabilities (colour etc) and different special character codes to do things like clear the screen. In order to use a particular type of terminal to its fullest ability UNIX must know about its capabilities. To do this the terminal must have an entry in the database of terminal characteristics that UNIX maintains.
For a user to actually be able to use a terminal it is necessary for the UNIX login process to be running for that terminal.
The login process on a terminal involves
- /etc/init,
The first process run on a UNIX system. It is init's responsibility to ensure that each terminal has a getty process running for it.
- getty,
Is responsible for setting up the characteristics of the line, displaying the login prompt, getting a username, and executing the login process with the username as an argument.
- login, and
Is responsible for logging the user into the system, obtaining and validating the password, and executing the user's login shell.
- a login shell.
The user's entry in the /etc/passwd file lists the program to execute as the user's login shell. The shell will in turn execute the appropriate startup scripts.
When the user quits their login shell the init process picks up this event and will rerun the getty process for that terminal.
The SysV Login Process
Under SysV the init process is controlled by the /etc/inittab configuration file (the format of /etc/inittab is discussed in the previous section). The inittab file must have an entry for each terminal that requires a getty process. Typical entries look like
c6:23:respawn:/etc/getty 9600 tty6
c7:23:respawn:/etc/getty 9600 ttys1
The getty process here takes two arguments
a label used as a lookup value for the file /etc/gettydefs, and
the device name for which the getty process is being executed.
The /etc/gettydefs file is used for setting various line options. /etc/gettydefs has the following format
label#initial flags#final flags#login prompt#next label
Table 10.3 explains each field from the gettydefs file.
Field Purpose
label the "key" to the particular entry
initial flags flags to set before running the login process
final flags flags to set after running the login process
login prompt the prompt to be displayed by getty before running login
next label points to the next label to use if this one is not valid (used to cycle through baud rates for modems)
Table 10.3. Fields for the /etc/gettydefs file.
The process for enabling logins for a new terminal on a SysV system includes
- have an entry in gettydefs file,
The system should come with most of the standard settings required for normal use so a new addition is usually not required.
- add a new entry to the inittab file to start the getty process for the terminal, and
- force init to reread the inittab file.
The new getty process will not be started until init reenters the specified run levels. Under SysV this is typically done using the command init -q
The BSD Login Process
UNIX versions based on pre 4.3 BSD use a different format than subsequent versions. In this section discussion will be restricted to the later versions. From 4.3 on BSD uses a single configuration file /etc/ttys with the following format.
device program terminal_type status
Field Purpose
device device file terminal is connected through
program program to be run if terminal is on (usually getty)
terminal_type typically the name of a terminal type listed
in /etc/termcap
status a list of key words separated by spaces,
keywords include
on should run program
off ignore the entry
secure root logins are allowed on
this terminal
Table 10.4. Format of the BSD /etc/ttys File.
Every terminal connected to a UNIX machine has an associated terminal driver process. This process maintains
- a list of characteristics about the current terminal, and
- a list of special characters and how they should be handled.
Probably the most common complaint from users is that when they hit particular keys the terminal doesn't do what is expected. Hitting the backspace key might produce a weird character or the cursor keys might not work under vi. These problems are caused by the terminal driver not being configured properly.
The tty command is sometimes useful. It displays the name
of the device file being used by the current terminal.
Initially these settings are set up by the system from the entries in the system's terminal configuration database. The stty command can be used to view and modify these settings.
Table 10.5 lists some of the terminal characteristics and Table 10.6 lists some of the special characters. To view the current settings try stty -a (the command might be stty all or stty everything depending on your system).
For example:
bash > stty -a
speed 9600 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol =
< undef>;
eol2 = < undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr
icrnl ixon ixoff
-iuclc -ixany -imaxbel
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0
tab0 bs0 vt0 ff0
isig icanon iext
Option Meaning
n bits per second
rows n lines to the screen
columns n columns on the screen
oddp odd parity
evenp even parity
-parity no parity
Table 10.5. Characteristics affected by stty.
Symbolic Name SysV default BSD default Meaning
ERASE # ^H erase one character of input
WERASE N/A ^W erase one word of input
KILL @ ^U erase entire line
EOF ^D ^D end of file
INTR ^? ^C interrupt current process
QUIT ^\\ ^\\ kill current process with core dump
STOP ^S ^S stop output to screen
START ^Q ^Q restart output to screen
SUSPEND N/A ^Z suspend current process
Table 10.6. Special Characters.
In these tables you will see character combinations like ^H and ^?. The ^ symbol is used in this case to signify the control key. So ^H could be rewritten CTRL-H.
A useful option of the stty command is sane. Entering stty sane when the terminal is behaving strangely will solve many problems.
It is possible to use I/O redirection to affect the settings of terminals other than the one you are currently using. Which form of I/O redirection (input or output) you use depends on your system. For BSD redirect the output of stty. For SysV redirect the input. (This will only work if you have the correct permissions on the device file associated with the terminal.
Exercise 10.2. Use the stty program to examine the current status for your terminal. Change the values for EOF ERASE and INTR experiment using the system with the changes.
Exercise 10.3. Change the values for rows and columns and observe the difference.
Exercise 10.4. Complete the process of connecting the terminal you started in question 10.1.
Exercise 10.5. If you are using a PC and a communications program you should be able to change the type of terminal you are using as part of the programs options. Change the type of terminal you are using. How does it effect using the terminal? Modify the appropriate files so that the system uses the correct entry from the terminal configuration database.
Different terminals have different keyboard layouts, escape codes and capabilities. For example one terminal will use one combination of characters to signify clearing the screen while another terminal will use another combination of characters.
If programs that wish to be able to clear the screen want to work on different terminals they must be able to find out how each terminal performs the operation. Under the UNIX operating system programs discover this information using
- the TERM (term if you're using csh) environment variable, and
- a system specific terminal database.
The shell variable TERM is usually initialised when a user first logs in. It will hold a unique identifier that signifies the type of terminal being used. This identifier is used to access the information about the terminal from the system's terminal database.
If the TERM variable is set incorrectly or the terminal does not have an entry in the terminal database problems likely to occur include
- keys not performing the expected task,
Hitting the backspace key doesn't do anything or displays a weird key combination.
- screen output not being written properly, or
The screen not scrolling properly, unexpected colours or characters are appearing.
- programs not working properly.
Full screen programs, vi for example, make use of special characteristics offered by most terminals. If the particular terminal you have doesn't have an entry in the terminal characteristics file it can't make use of these special characteristics.
It is the responsibility of various startup files (typically /etc/profile) to make sure that the TERM variable is initialised to the correct value.
For example:
The following is an example of how the TERM variable might be set.
if [ 'tty' = /dev/tty1 ]
then
TERM=vt100
elsif [ 'tty' = /dev/tty2 ]
then
TERM=tvi912b
else
TERM=console
fi
On this system the terminal connected to /dev/tty1 is a vt100 so that
is the value TERM is set to. The terminal on /dev/tty2 is a tvi912b
and it assumes that any other type of terminal is a console. The tty
command used here returns the device file used by the current terminal.
Once the TERM variable is set processes can use its value to access information in the terminal database. SysV and BSD based systems use different terminal databases.
Exercise 10.6. Make up some name for a terminal, e.g. myterm. Set the TERM shell variable to this value. Attempt to use the vi editor. What happens?
The SysV Terminal Database
The SysV terminal database is called terminfo. It is a collection of separate binary files. Each different terminal type will have its own separate binary terminfo file that describes its characteristics.
terminfo files are usually stored under the /usr/lib/terminfo directory. The terminfo sub-directory is further divided into directories with single character names. The actual terminfo files are stored under the separate directory corresponding to the first letter of the terminal identifier.
For example:
The terminfo file for the terminal type vt100 is stored in the
directory
/usr/lib/terminfo/v/vt100
The file for the terminal type tvi912b is in
/usr/lib/terminfo/t/tvi912b
terminfo files are compiled from a terminfo source file (an ASCII file) using the command tic. The format of terminfo source files will not be discussed here.
Some of the commands used by the terminfo database are listed in Table 10.7.
Command Purpose
tic compile a terminfo source file
infocmp list the source for a compiled terminfo entry
infocmp -C translate from a terminfo file to the termcap
format used by BSD systems
captoinfo translate from termcap format to terminfo format
Table 10.7. terminfo Related Commands.
The BSD Terminal Database
BSD systems use one central text based file as the terminal database. The file is /etc/termcap. It contains colon delimited entries for each type of terminal the system recognises.
The first field of every entry is a list of terminal names (separated by |) by which the system recognises a particular terminal. These names are what appears as the value for the TERM variable and is used by the system to look up an entry.
The rest of the entry for a terminal consists of various options that describe the way in which the terminal works. The various options will not be discussed here. They are described in the manual pages for the system if needed.
It is advisable to put the entries for the most used terminals on your site at the front of the termcap file to speed searching.
For example:
vt100|dec-vt100|vt100-am|vt100am|dec vt100:\
:do=^J:co#80:li#24:cl=50\E[;H\E[2J:sf=2*\ED:\
:le=^H:bs:am:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\
:ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\
E[m:md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:is=\E[1;24r\
E[24;1H:if=/usr/share/tabset/vt100:\
:rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\
:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\
:ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=2*\
EM:vt#3:xn:\:sc=\E7:rc=\E8:cs=\E[%i%d;%dr:
Exercise 10.7. Determine the type of terminal you are using and examine the entry for your terminal that is stored in your system's terminal database files. (On SysV based machines you'll have to use one of the commands listed in Table 10.5 to obtain the ASCII source.)
The process of adding terminals to a UNIX box is a reasonably straight forward process that can be plagued by strange and mysterious problems. Hopefully this section has introduced you to
- the hardware and software processes for adding terminals to a UNIX machine,
- the BSD and SysV configuration files for terminals,
- the commands tty and stty, and
- some of the problems that can arise while connecting a terminal.
The steps involved in connecting a terminal are
- choose a port on the computer,
- obtain the correct cable to connect the terminal to the port,
- configure the terminal,
- make and test the connection,
- ensure a correct entry for the terminal in the systems terminal configuration database,
- ensure that the TERM shell variable is set correctly,
- start the login process for the port.
10.1. List the different types of configuration files used in controlling a terminal.
10.2. List the specifics of the configuration files for the terminals on your system.
10.3. List and describe the hardware steps involved in connecting a terminal to a UNIX machine.
10.4. Describe the steps involved when a user logs onto a UNIX machine.
Previous | Next
David Jones (author)
Chris Hanson (html 08/09/96)