getsid(2)
๐ getsid โ get session ID ๐
okay bestie, so you know how every process on a Unix system is living its little life inside a session? yeah. this page is about peeking at which one. it's giving "who's your group chat admin" but for processes. no cap.
manual name: getsid(2) โ that's the system calls manual, section 2, the cool one. ๐ซถ
๐ LIBRARY
Standard C library (libc, -lc). just your normal libc, nothing exotic, we love that for her. โจ
๐ธ SYNOPSIS
#include <unistd.h>
pid_t getsid(pid_t pid);
Feature Test Macro Requirements for glibc (see feature_test_macros(7))
so lowkey glibc is gatekeeping this function behind macros, and you do need to set one or it won't show up. here's the tea:
getsid():_XOPEN_SOURCE >= 500||/* Since glibc 2.12: */_POSIX_C_SOURCE >= 200809L
yeah that || is doing the heavy lifting. pick a lane, either one works. ๐
๐ฆ DESCRIPTION
getsid() returns the session ID of the process with process ID pid. simple as that, she's a one-job icon.
and the bestie detail: if pid is 0, then getsid() returns the session ID of the calling process. it's like asking "what's my session" instead of pointing at someone else. main character energy, honestly. ๐
โญ RETURN VALUE
- on success: a session ID comes back, slay โจ
- on error:
(pid_t) -1is returned, anderrnogets set to tell you what went wrong ๐ญ
๐ ERRORS
here's the vibe check on what can go sideways:
EPERMโ so a process with process IDpiddoes exist, but it's not in the same session as the calling process, and the implementation considers that a whole error. like, blocked, respectfully. ๐ซESRCHโ no process with process IDpidwas found. it's not there. ghosted. literally nobody home. ๐ซฅ
๐ VERSIONS
okay so on Linux specifically: Linux does not return EPERM. noted, periodt.
๐ STANDARDS
POSIX.1-2024. certified, standardized, iconic.
๐ง HISTORY
she has lore: SVr4, SUSv1, Linux 2.0, POSIX.1-2001 XSI, POSIX.1-2008. a whole ancestry, we stan a legacy queen. ๐
๐ NOTES
if you wanna actually understand what sessions and session IDs are, go read credentials(7) โ that's where the whole concept gets explained. trust, iykyk. ๐
๐ฅ SEE ALSO
k that's the whole page bestie, you're officially a session ID expert now, no cap ๐
this was brought to you by Linux man-pages 6.20, dated 2026-02-08 โ stay curious, stan your syscalls, and don't forget your feature test macros or it literally will not compile, 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-2.0-or-later
- Copyright 1996, Andries E. Brouwer <aeb@cwi.nl>
- Copyright 2016, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms