[Chapter 38] 38.6 The Controlling Terminal
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:49:40Z

#

| Chapter 38 Starting, Stopping, and Killing Processes |

## 38.6 The Controlling Terminal

In article 38.5, we pointed out that the ps command needs special options (-x for BSD and -e for System V) to list processes without a controlling terminal.

But just what is a controlling terminal? Just what it sounds like: the terminal from which the process was started. In the ps listing, this is usually given as a tty, or terminal id. That ps entry usually corresponds to a serial port, or a pty (41.8). A pty or "pseudo-terminal" is a construct that makes a window or network login (1.33) look to the operating system just like a terminal.

In the ps listing, a tty might appear as `t1` for /dev/tty1, `p3` for /dev/ttyp3, or as some other designation, such as `co` for /dev/console, the full screen display of a workstation before any window system is started. Processes without a controlling terminal show a question mark (`?`).

How does a process "lose" its controlling terminal? Easy. Some processes, such as system "daemons" (1.14) never had one - they were started by system scripts that weren't started from any terminal, or they disconnected themselves from their controlling terminals. But it's also possible that you started a process running in the background, logged out, and logged back later or on another terminal to find it still running without a controlling terminal.

The tty command can be used to report which "terminal" you're currently connected to. For example:

>     % tty
>     /dev/ttyp2

Running tty without a controlling terminal gives the message `not` `a` `tty`.

- TOR

38.5 The ps Command |  | 38.7 Why ps Prints Some Commands in Parentheses