home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Unix Power ToolsUnix Power ToolsSearch this book

24.6. The Controlling Terminal

In Section 24.5, we pointed out that the ps command needs special options (-x for BSD-derived versions and -e for System V-type) 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. A pty or "pseudo-terminal" is a construct that makes a window or network login (Section 1.21) 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" (Section 1.10) 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 on later or on another terminal to find it still running without a controlling terminal. Disowned processes (Section 23.11) fit this category too.

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



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.