Open System Services System Calls Reference Manual (G06.25+, H06.03+)

Files tty(7)
NAME
tty - Is the general terminal interface
SYNOPSIS
#include <termios.h>
DESCRIPTION
The tty interface is the general interface for terminal devices. This interface supplies all the
functions needed for I/O over console serial lines, workstation screens, keyboards, and other ter-
minal devices. It consists of the special le /dev/tty and terminal drivers used for conversational
computing.
Much of a terminal interfaces performance is governed by the settings in the terminals termios
structure, which is dened in the termios.h header le. This structure provides denitions for
terminal input and output processing, control and local modes, and so on.
The Controlling Terminal
Open System Services supports the concept of a controlling terminal. Any process in the system
can have a controlling terminal associated with it. Certain events, such as the delivery of
keyboard-generated signals (for example, interrupt, quit, and suspend), affect all the processes in
the process group associated with the controlling terminal. The controlling terminal also deter-
mines the physical device that is accessed when the indirect device /dev/tty is opened.
In Open System Services, in accordance with the POSIX 1003.1 specication, a process must be
a session leader to allocate a controlling terminal. (This implies that the O_NOCTTY ag to the
open() function must be cleared.) The following code example illustrates the correct sequence
for obtaining a controlling tty (no error checking is shown). This code fragment calls the set-
sid() function to make the current process the group and session leader and to remove any con-
trolling tty that the process might already have. The code then opens a terminal and attaches it to
the current session as the controlling terminal. Note that the process must not already be a ses-
sion or process group leader and that the console must not already be the controlling tty of any
other session.
(void)setsid(); /* become session leader and */
/* lose controlling tty */
fd = open("/G/ZTNT/#PTY5", O_RDWR);
When a controlling terminal le is closed, pending input is removed and pending output is sent to
the receiving device.
When a terminal le is opened, the process blocks until a carrier signal is detected. If the open()
function is called with the O_NONBLOCK ag set, however, the process does not wait.
Instead, the rst read() or write() function call waits for a carrier to be established. If the CLO-
CAL mode is set in the termios structure, the driver assumes that modem control is not in effect
and so the open(), read(), and write() calls proceed without waiting for a carrier signal to be
established.
Process Groups
Each OSS process belongs to a process group with a specic process group ID. Each OSS pro-
cess belongs to the process group of its creating process. This enables related processes to be
signaled. Process group IDs are unique identiers that cannot be used for other system process
groups until the original process group is disbanded. Each process group also has a process
group leader. A process group leader has the same process ID as its process group.
Each process group belongs to a session. Each process in the process group also belongs to the
process groups session. A process that is not the process group leader can create its own session
and process group with a call to the setsid() function. That calling process then becomes the ses-
sion leader of the new session and of the new process group. The new session has no controlling
terminal until the session leader assigns one to it. The calling processs ID is assigned to the new
527186-003 Hewlett-Packard Company 1157