tcgetsid(3)

๐Ÿ’– tcgetsid(3) โ€” bestie edition ๐Ÿ’–

okay so real talk, this is tcgetsid, a lil function from the Library Functions Manual and it lives in the terminal-adjacent part of your brain. it's giving "who's your session daddy" energy and honestly? iconic.


โœจ NAME โœจ

tcgetsid โ€” get session ID ๐ŸŽ€

๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library โ€” that's libc, link it with -lc. no cap.

๐ŸŒธ SYNOPSIS ๐ŸŒธ

#define _XOPEN_SOURCE 500        /* See feature_test_macros(7) */
#include <termios.h>

pid_t tcgetsid(int fd);

yes bestie you literally have to #define _XOPEN_SOURCE 500 before the include, and there's a whole feature_test_macros(7) situation if you wanna know why. ๐Ÿ’…

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so what does it do? okay. tcgetsid() hands you back the session ID of the current session โ€” the one whose controlling terminal is the terminal attached to fd. ๐Ÿ”ฅ

and the vibe check here: that terminal has to be the controlling terminal of the calling process. it's not "any terminal you happen to be holding", it's the one your process is emotionally attached to. periodt.

๐Ÿซถ RETURN VALUE ๐Ÿซถ

when fd actually refers to the controlling terminal of your session โ€” slay โ€” tcgetsid() returns the session ID of that session. easy.

otherwise? it returns -1, and errno gets set to spill the tea about what went wrong. ๐Ÿ˜ญ

๐Ÿ’€ ERRORS ๐Ÿ’€

  • EBADF โ€” fd is not a valid file descriptor. girl, that's not a real fd, stop.
  • ENOTTY โ€” the calling process does not have a controlling terminal, OR it does have one but it's just not described by fd. either way, not it. ๐Ÿ™ˆ

๐Ÿ‘‘ ATTRIBUTES ๐Ÿ‘‘ (see attributes(7) for what these words even mean)

  • Interface: tcgetsid()
    • Attribute: Thread safety
    • Value: MT-Safe โœ… (go off, thread-safe king)

โญ STANDARDS โญ

POSIX.1-2008. it's official official.

๐ŸŒˆ HISTORY ๐ŸŒˆ

  • glibc 2.1. POSIX.1-2001.
  • and the fun lore: this function is implemented via the TIOCGSID ioctl(2), which has been present since Linux 2.1.71. vintage but thriving. ๐Ÿงš

๐Ÿ’œ SEE ALSO ๐Ÿ’œ


and that's the whole page, bestie ๐Ÿ“. this lil number came to you courtesy of Linux man-pages 6.20, dated 2026-02-08 โ€” shoutout to the man-pages girlies for keeping the docs fresh. now go get that session ID. ๐Ÿ’…โœจ๐Ÿฆ‹

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