[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    getsid(2) manual page Table of Contents

Name

getsid, setsid - get or set session ID

Synopsis

#include <sys/types.h>

pid_t getsid(pid_t pid);


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

pid_t setsid(void);

MT-Level

setsid() is Async-Signal-Safe

Description

The function getsid() returns the session ID of the process whose process ID is equal to pid. If pid is equal to (pid_t)0, getsid() returns the session ID of the calling process.

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.

See intro(2) for more information on process groups and controlling terminals.

Return Values

Upon successful completion, getsid() and setsid() return the session ID of the specified process. Otherwise, getsid() returns a value of (pid_t)-1 and sets errno to indicate an error, and setsid() returns a value of -1 and sets errno to indicate the error.

Errors

Under the following conditions, getsid() fails and sets errno to:
EPERM
The process whose process ID is equal to pid is not in the same session as the calling process, and the implementation does not allow access to the session ID of that process from the calling process.
ESRCH
There is no process with a process ID equal to pid.

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) , fork(2) , getpid(2) , setpgid(2)

Warnings

A call to setsid() by a process that is a process group leader will fail. A process can become a process group leader by being the last member of a pipeline started by a job control shell. Thus, a process that expects to be part of a pipeline, and that calls setsid(), should always first fork; the parent should exit and the child should call setsid(). This will ensure that the calling process will work reliably when started by both job control shells and non-job control shells.


Table of Contents