setpgid()

NAME

setpgid() - set process group

SYNOPSIS

#include <unistd.h>

int setpgid (pid_t pid, pid_t pgrp)

DESCRIPTION

The setpgid(2) function is used either to join an existing process group or to create a new process group within the session of the calling process. A new process group is created if and only if pid and pgrp denote the same process, and no errors occur.

Upon successful completion, the process group ID of the process specified by pid is set to pgrp.

If pid is zero, the process ID of the current process is used. If pgrp is zero, the process ID of the indicated group is used. This creates a new group, if the group doesn't already exist.

The setpgid(2) call will not fail if the indicated process or the leader of the indicated process group are zombies. (This is consistent with the behavior of BSD systems.)

RETURN VALUES

The setpgid(2) call returns 0 when the operation was successful. If the request failed, -1 is returned and the global variable errno indicates the reason.

ERRORS

The setpgid(2) call will fail and the process group will not be altered if:

[EACCES]
The value of pid matches the process ID of a child process and the child process has successfully executed one of the exec functions.
[EINVAL]
The value of the pgid argument is non-zero, is not equal to the ID of the indicated process, and is not equal to to the ID of any existing process group.
[EPERM]
The process indicated by pid is a session leader.

The value of pid matches the process ID of a child process of the calling process and the child process is not in the same session as the calling process.

The value of pgrp is valid, but does not match the process ID of the process indicated by pid and there is no process with a process group ID that matches pgid in the same session as the calling process.

[ESRCH]
The value of pid does not match the process ID of the calling process, or of a child of the calling process.

SEE ALSO

getpgrp(2)

setsid(2)

tcsetpgrp(2)