Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

setsid - create session and set process group ID

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

Optional
#include <sys/types.h>

pid_t setsid(void); 

Description

The setsid() function creates a new session, unless the calling process is process group leader. Following the return of this function, the calling process will be the session leader of this new session, the process group leader of a new process group, and will have no controlling terminal. The process group ID of the calling process is set to the process ID of the calling process. The calling process will be the only process in the new process group and the only process in the new session.

Return val.

Process group ID of the calling process


if successful.

(pid_t) -1

if unsuccessful. errno is set to indicate the error.

Errors

setsid() will fail if:

EPERM

The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process.

Notes

If the calling process is the last component of a pipeline started by a job control shell, the shell may make the calling process the process group leader. The other processes of the pipeline become members of that process group. In this case, the call to setsid() will fail. A process that calls setsid() and expects to be part of a pipeline should therefore always execute a fork() first; the parent process should exit, and the child process should call setsid(), thus ensuring that the process will work reliably regardless of whether or not it is called by a job-control shell (see the manual "POSIX Basics" [1 (Related publications)] and the manual "POSIX Commands" [2 (Related publications)]).

See also

setpgid(), sys/types.h, unistd.h.