DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

setsid(2)


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.

Return values

On success, setsid returns the calling process's session ID. On failure, setsid returns -1 and sets errno to identify the error.

Errors

In the following conditions, setsid fails and sets errno to:

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.

References

exec(2), exit(2), fork(2), getpid(2), getsid(2), intro(2), setpgid(2), setpgrp(2), signal(2), sigsend(2)

Notices

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.

Considerations for threads programming

This ID number is an attribute of the containing process and is shared by sibling threads.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004