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

PROLOG

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

NAME

12       setsid - create session and set process group ID
13

SYNOPSIS

15       #include <unistd.h>
16
17       pid_t setsid(void);
18
19

DESCRIPTION

21       The setsid() function shall  create  a  new  session,  if  the  calling
22       process  is not a process group leader. Upon return the calling process
23       shall be the session leader of this new session, shall be  the  process
24       group leader of a new process group, and shall have no controlling ter‐
25       minal. The process group ID of the calling process shall be  set  equal
26       to  the process ID of the calling process. The calling process shall be
27       the only process in the new process group and the only process  in  the
28       new session.
29

RETURN VALUE

31       Upon  successful completion, setsid() shall return the value of the new
32       process group ID of the calling process.  Otherwise,  it  shall  return
33       (pid_t)-1 and set errno to indicate the error.
34

ERRORS

36       The setsid() function shall fail if:
37
38       EPERM  The  calling  process  is already a process group leader, or the
39              process group ID of a process other  than  the  calling  process
40              matches the process ID of the calling process.
41
42
43       The following sections are informative.
44

EXAMPLES

46       None.
47

APPLICATION USAGE

49       None.
50

RATIONALE

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

FUTURE DIRECTIONS

72       None.
73

SEE ALSO

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