COHERENT manpages

This page displays the COHERENT manpage for setsid() [Set session identifier].

List of available manpages
Index


setsid() -- System Call (libc)

Set session identifier
#include <sys/types.h>
#include <unistd.h>
pid_t setsid ();

If the  calling process  is not a  process-group leader, setsid()  sets its
process-group  and  session  identifiers  to  its process  identifier,  and
releases the its controlling terminal.

If  all   goes  well,  setsid()  returns   the  calling  process's  session
identifier.  If  the calling process is already  a process-group leader, or
if process-group  identifier of another process equals  that of the calling
process, setsid() returns -1 and sets errno to EPERM.

See Also

libc,
unistd.h
POSIX Standard, §4.3.2

Notes

If the calling  process is the last member of  a pipeline started by a job-
control  shell, the  shell  may make  the calling  process a  process-group
leader.  The other processes of the pipeline become members of that process
group.  If this happens, the call to setsid() fails.

For this reason, a process that  calls setsid() and expects to be part of a
pipeline should  first fork:  the parent should  exit and the  child should
call  setsid().  This will  ensure  that the  process  works reliably  when
started by both job-control shells and non-job-control shells.