Manual page for getsid(2)
getsid, setsid - get or set session ID
SYNOPSIS
#include <sys/types.h>
pid_t getsid(pid_t pid);
#include <sys/types.h>
#include <unistd.h>
pid_t setsid(void);
MT-LEVEL
setsid() is Async-Signal-Safe
DESCRIPTION
The function
getsid()
returns the session ID of the process whose process
ID is equal to pid.
If pid is equal to (pid_t)0,
getsid()
returns the session ID of the calling process.
If the calling process is not already a process group leader,
setsid()
sets the
process group ID and session ID of the calling process to the process ID of
the calling process, and releases the process's controlling terminal.
See
intro.2
for more information on process groups and controlling terminals.
RETURN VALUES
Upon successful completion,
getsid()
and
setsid()
return the session ID of the specified process.
Otherwise,
getsid()
returns a value of (pid_t)-1 and sets errno to indicate an error,
and
setsid()
returns a value of -1 and sets errno to indicate the error.
ERRORS
Under the following conditions,
getsid()
fails and sets errno to:
- EPERM
-
The process whose process ID is equal to pid is not in the
same session as the calling process, and the implementation does not
allow access to the session ID of that process from the calling
process.
- ESRCH
-
There is no process with a process ID equal to pid.
setsid()
will fail and return an error if the following is true:
- EPERM
-
The calling process is already a process group leader, or
there are processes other than the calling process whose process
group ID is equal to the process ID of the calling process.
SEE ALSO
intro.2
exec.2
fork.2
getpid.2
setpgid.2
WARNINGS
A call to
setsid()
by a process that is a process group leader will fail.
A process can become a process group leader by being
the last member of a pipeline started by a job control shell.
Thus, a process that expects to be part of a pipeline,
and that calls
setsid(),
should always first fork; the parent should exit and the child should call
setsid().
This will ensure that the calling process will work reliably
when started by both job control shells and non-job control shells.
Created by unroff & hp-tools.
© by Hans-Peter Bischof. All Rights Reserved (1997).
Last modified 21/April/97