setpgid(3)
Name
setpgid − set process group (POSIX)
Syntax
#include <sys/types.h>
int
setpgid(pid, pgrp)
pid_t pid, pgrp;
Description
The setpgid function is used to either join an existing process group or create a new process group within the session of the calling process (see setsid().)). Upon successful completion, the process group ID of the process that has a process ID which matches pid is set to pgrp. If pid is zero, then the call applies to the current process. In addition, if pgrp is zero, the process ID of the indicated process is used.
This function is available only in the POSIX environment.
Return Values
The setpgid function returns 0 when the operation is successful. If the request fails, −1 is returned and the global variable errno indicates the reason.
Diagnostics
The setpgid function fails and the process group is not altered if one of the following occurs:
[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 an exec function.
[EINVAL] The value of the pgrp argument is less than zero or is not a supported value.
[EPERM] The process indicated by the pid argument is a session leader. The value of the pid argument 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 the pgrp argument does not match the process ID of the process indicated by the pid argument and there is no process with a process group ID that matches the value of the pgrp argument in the same session as the calling process.
[ESRCH] The value of the pid argument does not match the process ID of the calling process of a child process of the calling process.