SETPGID(2P)SETPGID(2P)NAMEsetpgid - (POSIX only) set process group
SYNOPSIS
#include <sys/types.h>
int setpgid(pid_t pid, gid_t pgid);
DESCRIPTION
The information in this specification applies only to POSIX
applications.
Setpgid is used to either join an existing process group or create a
new process group within the session of the calling process. The
process group of the specified process pid is set to pgid. If pid is
zero, then the call applies to the current process. If pgid is zero,
then the process ID of the current process is used.
A process may change its process group, or the process group of a child
if the child is in the same session and has not yet successfully called
an exec() function.
RETURN VALUE
Setpgid returns a value of 0 when the operation was successful. If the
request failed, -1 is returned and the global variable errno indicates
the reason.
ERRORS
Setpgid will fail and the process group will not be altered if one of
the following occur:
[EACCES] The value of pid 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 pgid argument is less than zero or is not a
supported value.
[EPERM] The process indicated by pid is a session leader.
[EPERM] The value of pid is valid, but 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.
[EPERM] The value of pgid does not match the process ID of the
process indicated by pid, and there is no process with a
process group ID that matches the value of the pgid
argument 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 process of the calling
process.
SEE ALSOexecve(2), getpgrp(2), setsid(2P), tcsetpgrp(2P)4th Berkeley Distribution August 1, 1992 SETPGID(2P)