setsid(2)

setsid2

Create session and set process group id

Usage

#include <unistd.h>

pid_t

setsid(void);

Overview

The setsid function creates a new session. The calling process is the session leader of the new session, is the process group leader of a new process group and has no controlling terminal. The calling process is the only process in either the session or the process group.

Upon successful completion, the setsid function returns the value of the process group ID of the new process group, which is the same as the process ID of the calling process.

Errors

If an error occurs, setsid returns -1 and the global variable errno is set to indicate the error, as follows:

[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.

Legacy synopsis

#include <sys/types.h> #include <unistd.h>

The include file ⟨sys/types.h⟩ is necessary.

Releases

155 releases since Mac OS X 10.0; the text changed 1 time.

  1. 10.0–10.4.11
  2. 10.5–26.5

Standards

The setsid function is expected to be compliant with the IEEE Std 1003.1-1988 (“POSIX.1”) specification.

From xnu 12377.121.6 in macOS 26.5. Parsed by carta from the page's mdoc source.