Chapter Contents

Previous

Next
setsid

setsid



Create Session and Specify Process Group ID

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

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

pid_t setsid(void);


DESCRIPTION

setsid creates a new session. The calling process is its session leader. The calling process is the process group leader of the new process group; it must not already be a process group leader. The calling process does not have a controlling terminal. The calling process begins as the only process in the new process group and in the new session. The process group ID of the new process group is equal to the process ID of the caller.


RETURN VALUE

setsid returns the value of the new process group ID of the calling process. setsid returns a -1 if not successful.


EXAMPLE

The following code fragment illustrates the use of setsid to create a new session:

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

pid_t pid;
.
.
.
printf("The process group ID is %d\n", (int) getpgrp());

if ((pid = setsid()) == -1)
   perror("setsid error");
else
   printf("The new process group ID is %d\n", (int) pid);
.
.
.

Note:    Also see the setpgid example.  [cautionend]


RELATED FUNCTIONS

setpgid


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.