1SETSID(P)                  POSIX Programmer's Manual                 SETSID(P)
2
3
4

NAME

6       setsid - create session and set process group ID
7

SYNOPSIS

9       #include <unistd.h>
10
11       pid_t setsid(void);
12
13

DESCRIPTION

15       The  setsid()  function  shall  create  a  new  session, if the calling
16       process is not a process group leader. Upon return the calling  process
17       shall  be  the session leader of this new session, shall be the process
18       group leader of a new process group, and shall have no controlling ter‐
19       minal.  The  process group ID of the calling process shall be set equal
20       to the process ID of the calling process. The calling process shall  be
21       the  only  process in the new process group and the only process in the
22       new session.
23

RETURN VALUE

25       Upon successful completion, setsid() shall return the value of the  new
26       process  group  ID  of the calling process.  Otherwise, it shall return
27       (pid_t)-1 and set errno to indicate the error.
28

ERRORS

30       The setsid() function shall fail if:
31
32       EPERM  The calling process is already a process group  leader,  or  the
33              process  group  ID  of  a process other than the calling process
34              matches the process ID of the calling process.
35
36
37       The following sections are informative.
38

EXAMPLES

40       None.
41

APPLICATION USAGE

43       None.
44

RATIONALE

46       The setsid() function is similar to the setpgrp() function of System V.
47       System V, without job control, groups processes into process groups and
48       creates new process groups via setpgrp(); only one process group may be
49       part of a login session.
50
51       Job  control allows multiple process groups within a login session.  In
52       order to limit job control actions so that they can  only  affect  pro‐
53       cesses  in  the same login session, this volume of IEEE Std 1003.1-2001
54       adds the concept of a session that is created via  setsid().  The  set‐
55       sid()  function also creates the initial process group contained in the
56       session.  Additional process groups can be created  via  the  setpgid()
57       function.   A System V process group would correspond to a POSIX System
58       Interfaces session containing a single POSIX process group.  Note  that
59       this  function requires that the calling process not be a process group
60       leader. The usual way to ensure this is true is to create a new process
61       with  fork()  and have it call setsid(). The fork() function guarantees
62       that the process ID of the new process  does  not  match  any  existing
63       process group ID.
64

FUTURE DIRECTIONS

66       None.
67

SEE ALSO

69       getsid()  ,  setpgid()  ,  setpgrp()  ,  the Base Definitions volume of
70       IEEE Std 1003.1-2001, <sys/types.h>, <unistd.h>
71
73       Portions of this text are reprinted and reproduced in  electronic  form
74       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
75       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
76       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
77       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
78       event of any discrepancy between this version and the original IEEE and
79       The Open Group Standard, the original IEEE and The Open Group  Standard
80       is  the  referee document. The original Standard can be obtained online
81       at http://www.opengroup.org/unix/online.html .
82
83
84
85IEEE/The Open Group                  2003                            SETSID(P)
Impressum