.\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: GPL-1.0-or-later .\" .TH TIOCSCTTY 2const (date) "Linux man-pages (unreleased)" .SH NAME TIOCSCTTY, TIOCNOTTY \- controlling the terminal .SH LIBRARY Standard C library .RI ( libc ,\~ \-lc ) .SH SYNOPSIS .nf .BR "#include " " /* Definition of " TIOC*TTY " constants */" .B #include .P .BI "int ioctl(int " fd ", TIOCSCTTY, int " arg ); .BI "int ioctl(int " fd ", TIOCNOTTY);" .fi .SH DESCRIPTION .TP .B TIOCSCTTY Make the given terminal the controlling terminal of the calling process. The calling process must be a session leader and not have a controlling terminal already. For this case, .I arg should be specified as zero. .IP If this terminal is already the controlling terminal of a different session group, then the ioctl fails with .BR EPERM , unless the caller has the .B CAP_SYS_ADMIN capability and .I arg equals 1, in which case the terminal is stolen, and all processes that had it as controlling terminal lose it. .TP .B TIOCNOTTY If the given terminal was the controlling terminal of the calling process, give up this controlling terminal. If the process was session leader, then send .B SIGHUP and .B SIGCONT to the foreground process group and all processes in the current session lose their controlling terminal. .SH RETURN VALUE On success, 0 is returned. On error, \-1 is returned, and .I errno is set to indicate the error. .SH ERRORS .TP .B EPERM Insufficient permission. .SH SEE ALSO .BR ioctl (2), .BR ioctl_tty (2)