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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms