SETSID(3POSIX)
π SETSID(3POSIX) π
okay bestie, welcome to the POSIX Programmer's Manual β¨ this one's from the POSIX Programmer's Manual volume, and here's the tea: the Linux implementation of this interface may differ (so go check the matching Linux manual page for the deets on Linux behavior), or honestly the interface might not even be implemented on Linux at all. π no cap.
πΈ NAME πΈ
setsid β create session and set process group ID π
β¨ SYNOPSIS β¨
#include <unistd.h>
pid_t setsid(void);
π¦ DESCRIPTION π¦
so here's the whole vibe: setsid() shall create a new session, but only if the calling process is not a process group leader. like, that's the whole condition. the moment it returns, 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 π«
also the process group ID of the calling process shall be set equal to the process ID of the calling process. and bestie, the calling process shall be the only process in the new process group and the only process in the new session. solo main character energy fr fr. π
π RETURN VALUE π
upon successful completion, setsid() shall return the value of the new process group ID of the calling process π 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. it's giving "you cannot sit with us" π
heads up: the following sections are informative.
π EXAMPLES π
None.
like, literally none. nothing. empty. a void. π«Ά
π APPLICATION USAGE π
None.
also none. we love a low-effort section, iconic behavior. π
π§ RATIONALE π§
okay so the 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(); and only one process group may be part of a login session.
now job control allows multiple process groups within a login session. so 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 note (this part matters, bestie): 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. π«‘ periodt.
π FUTURE DIRECTIONS π
None.
π SEE ALSO π
getsid()setpgid()setpgrp()
and from the Base Definitions volume of POSIX.1β2017: <sys_types.h>, <unistd.h> π
π 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!! mwah π this was brought to you by IEEE/The Open Group, 2017, page SETSID(3POSIX) β go forth and detach from your controlling terminal, you absolute icon π¦β¨π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms