This function is used to set a terminal's foreground process group ID.
The argument filedes is a descriptor which specifies the terminal;
pgid specifies the process group. The calling process must be a
member of the same session as pgid and must have the same
For terminal access purposes, this function is treated as output. If it
is called from a background process on its controlling terminal,
normally all processes in the process group are sent a
signal. The exception is if the calling process itself is ignoring or
SIGTTOU signals, in which case the operation is
performed and no signal is sent.
0. A return value of
-1 indicates an error. The following
conditions are defined for this function:
- The filedes argument is not a valid file descriptor.
- The pgid argument is not valid.
- The system doesn't support job control.
- The filedes isn't the controlling terminal of the calling process.
- The pgid isn't a process group in the same session as the calling