Creates a session and sets the process group ID.
#include <unistd.h>
pid_t setsid (void)
The setsid subroutine creates a new session if the calling process is not a process group leader. Upon return, the calling process is the session leader of this new session, the process group leader of a new process group, and has no controlling terminal. The process group ID of the calling process is set equal to its process ID. The calling process is the only process in the new process group and the only process in the new session.
Upon successful completion, the value of the new process group ID is returned. Otherwise, (pid_t) -1 is returned and the errno global variable is set to indicate the error.
The setsid subroutine
is unsuccessful if the following is true:
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. |
This subroutine is part of Base Operating System (BOS) Runtime.
The fork subroutine, getpid, getpgrp, or getppid subroutine, setpgid (setpgid or setpgrp Subroutine) subroutine, setpgrp (setpgid or setpgrp Subroutine) subroutine.