setsid(2)


NAME

   setsid - creates a session and sets the process group ID

SYNOPSIS

   #include <unistd.h>

   pid_t setsid(void);

DESCRIPTION

   setsid()  creates a new session if the calling process is not a process
   group leader.  The calling process is the leader  of  the  new  session
   (i.e., its session ID is made the same as its process ID).  The calling
   process also becomes the process group leader of a new process group in
   the session (i.e., its process group ID is made the same as its process
   ID).

   The calling process will be the only process in the new  process  group
   and in the new session.

   Initially, the new session has no controlling terminal.  For details of
   how a session acquires a controlling terminal, see credentials(7).

RETURN VALUE

   On success, the (new) session ID of the calling  process  is  returned.
   On  error,  (pid_t) -1  is  returned,  and errno is set to indicate the
   error.

ERRORS

   EPERM  The process group ID of  any  process  equals  the  PID  of  the
          calling  process.   Thus,  in  particular, setsid() fails if the
          calling process is already a process group leader.

CONFORMING TO

   POSIX.1-2001, POSIX.1-2008, SVr4.

NOTES

   A child created via fork(2) inherits  its  parent's  session  ID.   The
   session ID is preserved across an execve(2).

   A  process  group leader is a process whose process group ID equals its
   PID.  Disallowing a process group leader from calling setsid() prevents
   the  possibility  that  a  process  group leader places itself in a new
   session while other processes  in  the  process  group  remain  in  the
   original  session;  such  a  scenario  would break the strict two-level
   hierarchy of sessions and process groups.  In order  to  be  sure  that
   setsid() will succeed, call fork(2) and have the parent _exit(2), while
   the child (which by definition can't be a process group  leader)  calls
   setsid().

   If  a  session has a controlling terminal, and the CLOCAL flag for that
   terminal is not set, and a terminal hangup  occurs,  then  the  session
   leader is sent a SIGHUP signal.

   If  a process that is a session leader terminates, then a SIGHUP signal
   is sent to  each  process  in  the  foreground  process  group  of  the
   controlling terminal.

SEE ALSO

   setsid(1),     getsid(2),    setpgid(2),    setpgrp(2),    tcgetsid(3),
   credentials(7), sched(7)

COLOPHON

   This page is part of release 4.09 of the Linux  man-pages  project.   A
   description  of  the project, information about reporting bugs, and the
   latest    version    of    this    page,    can     be     found     at
   https://www.kernel.org/doc/man-pages/.


More Linux Commands

manpages/isatty.3.html
isatty(3) - test whether a file descriptor refers to a termi
The isatty() function tests whether fd is an open file descriptor referring to a terminal. RETURN VALUE isatty() returns 1 if fd is an open file descriptor refe

manpages/glClientActiveTextureARB.3gl.html
glClientActiveTextureARB(3gl) - select active texture unit
glClientActiveTextureARB selects the vertex array client state parameters to be modified by glTexCoordPointer, and enabled or disabled with glEnableClientState

manpages/daemon.3.html
daemon(3) - run in the background - Linux manual page.......
The daemon() function is for programs wishing to detach themselves from the controlling terminal and run in the background as system daemons. If nochdir is zero

manpages/ssh-keysign.8.html
ssh-keysign(8) - ssh helper program for host-based authentic
ssh-keysign is used by ssh-add(1) to access the local host keys and generate the digital signature required during host-based authentication with SSH protocol v

manpages/x509.3ssl.html
x509(3ssl) - X.509 certificate handling - Linux manual page
A X.509 certificate is a structured grouping of information about an individual, a device, or anything one can imagine. A X.509 CRL (certificate revocation list

manpages/dga.1.html
dga(1) - test program for the XFree86-DGA extension.........
Dga is a simple test client for the XFree86-DGA extension. It fills the screen with a different colour for each key pressed. It prints some basic framebuffer pa

manpages/FcStrCopyFilename.3.html
FcStrCopyFilename(3) - create a complete path from a filenam
FcStrCopyFilename constructs an absolute pathname from s. It converts any leading ~ characters in to the value of the HOME environment variable, and any relativ

manpages/squidclient.1.html
squidclient(1) - a simple HTTP web client - Linux man page
squidclient is a tool providing a command line interface for retrieving URLs. Designed for testing any HTTP 0.9, 1.0, or 1.1 web server or proxy. This tool can

manpages/cimagl.3.html
cimagl(3) - get imaginary part of a complex number (ManPage)
The cimag() function returns the imaginary part of the complex number z. One has: z = creal(z) + I * cimag(z) VERSIONS These functions first appeared in glibc i

manpages/netscsid.1.html
netscsid(1) - write data to optical disk media (Man Page)...
wodim is used to record data or audio Compact Discs on an Orange Book CD-Recorder or to write DVD media on a DVD-Recorder. The device is the device file or labe

manpages/Pod::Usage.3pm.html
Pod::Usage(3pm) - print a usage message from embedded pod do
pod2usage will print a usage message for the invoking script (using its embedded pod documentation) and then exit the script with the desired exit status. The u

manpages/islower_l.3.html
islower_l(3) character classification functions (Man Page)
These functions check whether c, which must have the value of an unsigned char or EOF, falls into a certain character class according to the specified locale. T





We can't live, work or learn in freedom unless the software we use is free.