[Previous]
[Contents]
[Next]

setpgid()

join or create a process group

Synopsis:

#include <unistd.h>
int setpgid( pid_t pid, pid_t pgid );

Description:

The setpgid() function is used either to join an existing process group or to create a new process group within the session of the calling process. The process group ID of a session leader will not change. Upon successful completion, the process group ID of the process with a process ID matching pid is set to pgid. As a special case, either pid or pgid may be specified as zero, meaning that the process ID of the calling process is to be used.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EACCES
The value of the pid argument matches the process ID of a child process of the calling process, and the child process has successfully executed one of the exec... functions.
EINVAL
The value of pgid is less than zero.
ENOSYS
The setpgid() function isnt supported by this implementation (included for POSIX compatibility).
EPERM
The calling process doesnt have sufficient privilege to set the process group ID pgid on process pid.
ESRCH
The process pid doesnt exist.

Examples:

/*
 * The process joins process group 0
 */
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

void main()
  {
    if( setpgid( getpid(), 0 ) == -1 ) {
    perror( "segpgid" );
    }
    printf( "%d belongs to process group %d\n",
         getpid(), getpgrp() );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

errno, setgid(), setuid(), setsid()


[Previous]
[Contents]
[Next]