[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4 Files Reference

tty Special File

Purpose

Supports the controlling terminal interface.

Description

For each process, the /dev/tty special file is a synonym for the controlling terminal associated with that process. By directing messages to the tty file, application programs and shell sequences can ensure that the messages are written to the terminal even if output is redirected. Programs can also direct their display output to this file so that it is not necessary to identify the active terminal.

A terminal can belong to a process as its controlling terminal. Each process of a session that has a controlling terminal has the same controlling terminal. A terminal can be the controlling terminal for one session at most. If a session leader has no controlling terminal and opens a terminal device file that is not already associated with a session (without using the O_NOCTTY option of the open subroutine), the terminal becomes the controlling terminal of the session leader. If a process that is not a session leader opens a terminal file or if the O_NOCTTY option is used, that terminal does not become the controlling terminal of the calling process. When a controlling terminal becomes associated with a session, its foreground process group is set to the process group of the session leader.

The controlling terminal is inherited by a child process during a fork subroutine. A process cannot end the association with its controlling terminal by closing all of its file descriptors associated with the controlling terminal if other processes continue to have the terminal file open. A process that is not already the session leader or a group leader can break its association with its controlling terminal by using the setsid subroutine. Other processes remaining in the old session retain their association with the controlling terminal.

When the last file descriptor associated with a controlling terminal is closed (including file descriptors held by processes that are not in the controlling terminal's session), the controlling terminal is disassociated from its current session. The disassociated controlling terminal can then be acquired by a new session leader.

A process can also remove the association it has with its controlling terminal by opening the tty file and issuing the following ioctl command:

ioctl (FileDescriptor, TIOCNOTTY, 0):

It is often useful to disassociate server processes from their controlling terminal so they cannot receive input from or be stopped by the terminal.

Implementation Specifics

This device driver supports the POSIX and Berkeley line disciplines, as well as AIX compatibility mode.

The tty special file is part of Base Operating System (BOS) Runtime.

Related Information

The fork subroutine, open subroutine, setsid subroutine.

Special Files Overview.

The tty Subsystem Overview in AIX General Programming Concepts: Writing and Debugging Programs.


[ Previous | Next | Contents | Glossary | Home | Search ]