TIOCSCTTY(2const)
π TIOCSCTTY(2const) β controlling the terminal π
okay bestie, gather round, because this one is a whole thing about who owns your terminal. it's a manual page from the 2const section (constants, iykyk), and it's lowkey one of the most "who's the main character of this session" pages in the whole man-pages collection. let's go π«Ά
πΈ LIBRARY
Standard C library (libc, -lc)
β¨ SYNOPSIS
#include <asm/termbits.h> /* Definition of TIOC*TTY constants */
#include <sys/ioctl.h>
int ioctl(int fd, TIOCSCTTY, int arg);
int ioctl(int fd, TIOCNOTTY);
like yes, they're both just ioctl calls, but they do diametrically opposite things and that's the drama π
π DESCRIPTION
TIOCSCTTY
Make the given terminal the controlling terminal of the calling process. so you're basically claiming it, slay π
but bestie, there are receipts:
- The calling process must be a session leader.
- It must not already have a controlling terminal.
if both of those are true for you, then arg should be specified as zero.
now here's the messy part π β if this terminal is already the controlling terminal of a different session group, then the ioctl fails with EPERM. full stop. *unless*β¦ the caller has the CAP_SYS_ADMIN capability and arg equals 1. in that case the terminal is stolen, and every single process that had it as its controlling terminal loses it. no cap, that's the vibe. iconic but also kind of brutal π
TIOCNOTTY
the reverse bestie. if the given terminal was the controlling terminal of the calling process, this gives up that controlling terminal. releasing it. letting it go. we're moving on β¨
and if the process was a session leader β okay listen closely, this part matters β then it sends SIGHUP and SIGCONT to the foreground process group, and all processes in the current session lose their controlling terminal. everybody's terminalless now. it's giving apocalypse π¦
π RETURN VALUE
On success, 0 is returned. On error, -1 is returned, and errno is set to indicate the error. classic. the eternal duality of the Unix return value π
π ERRORS
EPERMβ Insufficient permission.
π₯ SEE ALSO
and that's the whole page bestie!! π this one came to you from Linux man-pages 6.20, dated 2026-02-08, filed under TIOCSCTTY(2const) β go forth and claim your terminals responsibly, mwah ππ§
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-1.0-or-later
- Copyright 2002, Walter Harms <walter.harms@informatik.uni-oldenburg.de>
- Copyright 2002, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms