If a process is in the foreground process group of its controlling terminal, it will be allowed to read from this terminal, as described in the section “Input processing and reading data” . For those implementations that support job control, any attempt by a process in a background process group to read from its controlling terminal will cause its process group to be sent a SIGTTIN signal unless one of the following special cases applies:
The reading process is ignoring or blocking the
SIGTTINsignal.The process group of the reading process is orphaned.
In the above cases, the read() function returns -1, with errno set to EIO, and no signal is sent. The default action of the SIGTTIN signal is to stop the process to which it is sent (see also signal.h).
If a process is in the foreground process group of its controlling terminal, then write operations are allowed as described in the section “Writing data and output processing”. Attempts by a process in a background process group to write to its controlling terminal will cause the process group to be sent a SIGTTOU signal unless one of the following special cases apply:
If
TOSTOPis not set, or ifTOSTOPis set and the process is ignoring or blocking theSIGTTOUsignal, then the process is allowed to write to the terminal and theSIGTTOUsignal is not sent.If
TOSTOPis set and the process group of the writing process is orphaned, and the writing process is not blockingSIGTTOU, thewrite()function returns -1, witherrnoset toEIO, and no signal is sent.
Certain function calls that set terminal parameters are treated in the same way as the write() function, except that TOSTOP is ignored; that is, the effect is identical to that of an attempt to write to the terminal when TOSTOP is set (see also section “Local modes”, tcdrain(), tcflow(), tcflush(), tcsendbreak() and tcsetattr()).