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โfdis 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 byfd. 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
TIOCGSIDioctl(2), which has been present since Linux2.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
- 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