setsid(2) setsid(2) NAME setsid - set session ID SYNOPSIS #include <sys/types.h> #include <unistd.h> pid_t setsid(void); DESCRIPTION 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. 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), exit(2), fork(2), getpid(2), getpgid(2), getsid(2), setpgid(2), setpgrp, signal(2), sigsend(2), sigaction(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. In this case, the call to setsid will fail. For this reason, a process that calls setsid and expects to be part of a pipeline should always first fork; the parent should exit and the child should call setsid, thereby insuring that the process will work reliably when started by both job control shells and non-job control shells. DIAGNOSTICS Upon successful completion, setsid returns the calling process's session ID. Otherwise, a value of -1 is returned and errno is set to indicate the error. Page 1