Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
All of the processes in a session may have a (single) controlling terminal. Upon creation, a session has no controlling terminal; the controlling terminal is established when the session leader first opens a terminal that is not already the controlling terminal for a session, unless the O_NOCTTY flag is specified when calling open(). A terminal may be the controlling terminal for at most one session.
Note:
SUSv3 specifies the function tcgetsid(int fd) (prototyped in <termios.h>), which returns the ID of the session associated with the controlling terminal specified by fd. This function is provided in glibc (where it is implemented using the ioctl() TIOCGSID operation).