SETSID(3P)
π SETSID(3P) β POSIX Programmer's Manual π
okay bestie, welcome to the POSIX Programmer's Manual page for setsid, which lives in section 3P. pull up a chair, we're gonna talk about sessions π«Ά
πΈ PROLOG πΈ
real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, go read the corresponding Linux manual page for the deets on Linux behavior, bestie), or β plot twist β the interface might not even be implemented on Linux at all. π
β¨ NAME β¨
setsid β create session and set process group ID
π¦ SYNOPSIS π¦
#include <unistd.h>
pid_t setsid(void);
no arguments, no drama, she takes nothing and gives you a whole new session. iconic. π
π DESCRIPTION π
so here's the vibe: the setsid() function shall create a new session, if the calling process is not a process group leader. that "if" is doing a LOT of heavy lifting, keep that in mind.
upon return, the calling process shall be:
- the session leader of this new session
- the process group leader of a new process group
- and shall have no controlling terminal (yes, fr fr, none)
the process group ID of the calling process shall be set equal to the process ID of the calling process. and like, the calling process shall be the only process in the new process group and the only process in the new session. main character energy, literally the only one there. π
π RETURN VALUE π
upon successful completion, setsid() shall return the value of the new process group ID of the calling process. slay.
otherwise, it shall return -1 and set errno to indicate the error. π
π ERRORS π
the setsid() function shall fail if:
EPERMβ the calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process. basically: you're already the leader of something, or someone out there is wearing your ID. not the vibe. π«
the following sections are informative. (so like, they're the bonus content, not the rules-rules, but still read them bestie π)
π EXAMPLES π
None. β nothing here, moving on, we stay unbothered. π
π APPLICATION USAGE π
None. β also empty. two for two on the "no notes" energy. β¨
π§ RATIONALE π§
okay history lesson, and honestly it's giving lore:
the setsid() function is similar to the setpgrp() function of System V. System V, without job control, groups processes into process groups and creates new process groups via setpgrp(); only one process group may be part of a login session.
job control allows multiple process groups within a login session. in order to limit job control actions so that they can only affect processes in the same login session, this volume of POSIX.1β2017 adds the concept of a session that is created via setsid(). the setsid() function also creates the initial process group contained in the session. additional process groups can be created via the setpgid() function. a System V process group would correspond to a POSIX System Interfaces session containing a single POSIX process group.
and here's the part everyone forgets: note that this function requires that the calling process not be a process group leader. the usual way to ensure this is true is to create a new process with fork() and have it call setsid(). the fork() function guarantees that the process ID of the new process does not match any existing process group ID. so like β fork first, then setsid, and you're golden. π
β FUTURE DIRECTIONS β
None. β the future is bright and also empty. she's stable, she's fine, she's not going anywhere. π¦
π SEE ALSO π
getsid()setpgid()setpgrp()
the Base Definitions volume of POSIX.1β2017, <sys_types.h>, <unistd.h> β go read those too, iykyk π
π COPYRIGHT π
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie!! π this one came from IEEE/The Open Group, 2017 β so like, shoutout to them for the original, and shoutout to YOU for reading all the way to the bottom. periodt. πβ¨π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms