SETSID(3)                  POSIX Programmer's Manual                 SETSID(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       setsid -- create session and set process group ID

SSYYNNOOPPSSIISS
       #include <unistd.h>

       pid_t setsid(void);

DDEESSCCRRIIPPTTIIOONN
       The _s_e_t_s_i_d() function shall create a new session, if the calling
       process is not a process group leader. Upon return the calling process
       shall be the session leader of this new session, shall be the process
       group leader of a new process group, and shall have no controlling
       terminal. The process group ID of the calling process shall be set
       equal to the process ID of the calling process. The calling process
       shall be the only process in the new process group and the only process
       in the new session.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _s_e_t_s_i_d() shall return the value of the new
       process group ID of the calling process. Otherwise, it shall return -1
       and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _s_e_t_s_i_d() function shall fail if:

       EEPPEERRMM  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.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       The _s_e_t_s_i_d() function is similar to the _s_e_t_p_g_r_p() function of System V.
       System V, without job control, groups processes into process groups and
       creates new process groups via _s_e_t_p_g_r_p(); 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 _s_e_t_s_i_d().  The _s_e_t_s_i_d()
       function also creates the initial process group contained in the
       session. Additional process groups can be created via the _s_e_t_p_g_i_d()
       function. A System V process group would correspond to a POSIX System
       Interfaces session containing a single POSIX process group. 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 _f_o_r_k() and have it call _s_e_t_s_i_d().  The _f_o_r_k() function guarantees
       that the process ID of the new process does not match any existing
       process group ID.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _g_e_t_s_i_d(), _s_e_t_p_g_i_d(), _s_e_t_p_g_r_p()

       The Base Definitions volume of POSIX.1-2017, <<ssyyss__ttyyppeess..hh>>, <<uunniissttdd..hh>>

CCOOPPYYRRIIGGHHTT
       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 .



IEEE/The Open Group                  2017                            SETSID(3)
