Processes in the foreground job of a controlling terminal have unrestricted access to that terminal; background processes do not. This section describes in more detail what happens when a process in a background job tries to access its controlling terminal.
When a process in a background job tries to read from its controlling
terminal, the process group is usually sent a SIGTTIN
signal.
This normally causes all of the processes in that group to stop (unless
they handle the signal and don't stop themselves). However, if the
reading process is ignoring or blocking this signal, then read
fails with an EIO
error instead.
Similarly, when a process in a background job tries to write to its
controlling terminal, the default behavior is to send a SIGTTOU
signal to the process group. However, the behavior is modified by the
TOSTOP
bit of the local modes flags (see Local Modes). If
this bit is not set (which is the default), then writing to the
controlling terminal is always permitted without sending a signal.
Writing is also permitted if the SIGTTOU
signal is being ignored
or blocked by the writing process.
Most other terminal operations that a program can do are treated as reading or as writing. (The description of each operation should say which.)
For more information about the primitive read
and write
functions, see I/O Primitives.