TIOCSPGRP(2const)

πŸ’– TIOCSPGRP β€” process group and session ID πŸ’–

okay bestie, gather round, because today we're talking about TIOCSPGRP (and its two lil siblings TIOCGPGRP and TIOCGSID) from section 2const of the Linux manual. yes, the manual name is right there in the title: TIOCSPGRP(2const). it's giving terminal-ioctl royalty, and i'm obsessed. πŸ‘‘


✨ NAME ✨

TIOCGPGRP, TIOCSPGRP, TIOCGSID β€” process group and session ID 🫢


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc)


🌸 SYNOPSIS 🌸

#include <asm/termbits.h>  /* Definition of TIOC* constants */
#include <sys/ioctl.h>

int ioctl(int fd, TIOCGPGRP, pid_t *argp);
int ioctl(int fd, TIOCSPGRP, const pid_t *argp);
int ioctl(int fd, TIOCGSID, pid_t *argp);

πŸ¦‹ DESCRIPTION πŸ¦‹

Three constants, three vibes. Let's break them down one by one, no gatekeeping here. πŸ’…

TIOCGPGRP πŸ‘€

When it works, it's equivalent to *argp = tcgetpgrp(fd).

It gets the process group ID of the foreground process group on this terminal. basically: "who's running the show on this tty rn?" and now u know. πŸ”₯

TIOCSPGRP πŸ‘‘

Equivalent to tcsetpgrp(fd, *argp).

It sets the foreground process group ID of this terminal. yes ma'am, you're handing over the aux cord of the tty. main character energy fr fr. πŸŽ€

TIOCGSID 🌈

When it works, it's equivalent to *argp = tcgetsid(fd).

It gets the session ID of the given terminal. BUT β€” and this is important bestie β€” it fails with the error ENOTTY if the terminal is not a master pseudoterminal and not our controlling terminal. Strange. 😭 like, okay, sure, whatever u say king. πŸ’€


⭐ RETURN VALUE ⭐

  • On success, 0 is returned. slay.
  • On error, -1 is returned, and errno is set to indicate the error. not slay. πŸ™ˆ

πŸ’€ ERRORS πŸ’€

  • ENOTTY β€” The terminal is not a master pseudoterminal and not our controlling terminal. (the terminal is simply not that girl πŸ’…)
  • EPERM β€” Insufficient permission. (u don't have the pass, bestie, and the bouncer is not negotiable 🚫)

πŸ” SEE ALSO πŸ”


quick vibe check: every flag, every error, every return value stayed exactly where it was. i would never edit the source material, that's not the move. 🫢

and that's the whole page, bestie! this was brought to u by Linux man-pages 6.20, dated 2026-02-08, under the TIOCSPGRP(2const) era of the documentation timeline. tysm for reading, go set some foreground process groups responsibly, and remember: no cap, ENOTTY is just a terminal having a boundaries moment. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ 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