Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/setsid.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/setsid.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/setsid.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/setsid.html on line 8

setsid()

Create a new session

Synopsis:

#include <unistd.h>

pid_t setsid( void );

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The setsid() function creates a new session with the calling process becoming the process group leader with no controlling terminal. The process group ID of the calling process is set to the process ID of the calling process. The calling process is the only process in the new process group, and is also the only process in the new session.

If the calling process is already a process group leader, a new session isn't created and an error is returned.

Returns:

The new process group ID for the calling process, or -1 if an error occurred (errno is set).

Errors:

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.

Examples:

/*
 * You can only become a session leader if you are not
 * a process group leader that is the default for a
 * command run from the shell.
 */

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

int main( void )
  {

    if( fork() )
      {
      if( setsid() == -1 )
        perror( "parent: setsid" );
      else
        printf( "parent: I am a session leader\n" );
      }
    else
      {
      if( setsid() == -1 )
        perror( "child: setsid" );
      else
        printf( "child: I am a session leader\n" );
      }
    return EXIT_SUCCESS;
  }

Classification:

POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

errno, getsid(), setpgid()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/setsid.html on line 155

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/setsid.html on line 155