When you type a command, it can read your keyboard and print to your screen. That works because it is connected to a terminal. For most processes started from a shell, that terminal is also their controlling terminal.
Which terminal am I using?
$ tty
/dev/pts/0A name like pts/0 is a pseudo-terminal. You get one from a terminal window or an SSH session. A name like tty1 is a virtual console, the full-screen text login that many Linux machines offer. Terminals appear as device files under /dev.
The TTY column
ps shows each process's controlling terminal:
$ ps -eo pid,tty,comm
PID TTY COMMAND
1 ? systemd
778 ? sshd
2145 pts/0 bash
2388 pts/1 vimA ? means the process has no controlling terminal. This is normal for daemons, the background services that start at boot. They are not tied to anyone's window, so they write to log files or the system journal instead.
Keyboard signals
The controlling terminal is how some key presses reach programs. The kernel sends a signal to the foreground process group, which is the command or pipeline you are currently waiting on:
Ctrl+CsendsSIGINT, which usually ends the program.Ctrl+ZsendsSIGTSTP, which pauses it.Ctrl+\sendsSIGQUIT, which ends it and may produce a core dump.
Background commands in the same terminal do not receive these key presses.
When the terminal goes away
If you close the window or your SSH connection drops, the terminal hangs up. The kernel and shell send SIGHUP ("hang up") to processes connected to it, and by default that signal ends a process. This is why a long job can die when you disconnect.
You can protect a command with nohup, which makes it ignore SIGHUP:
$ nohup ./backup.sh &
[1] 2501
nohup: ignoring input and appending output to 'nohup.out'Terminal multiplexers such as tmux and screen solve the same problem differently. They keep their own terminal alive on the server, so you can reconnect to it later. They may need to be installed first.
Try it
Run tty in two separate terminal windows and compare the results. Then run ps -t pts/0, using one of the names you saw, to list the processes on that terminal. The processes and cron lab gives you a shell to experiment in.
Check your understanding
The controlling terminal
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.