setpgid() - set process group
#include <unistd.h>
int setpgid (pid_t pid, pid_t pgrp)
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.)
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.
The setpgid(2) call will fail and the process group will not be altered if:
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.
getpgrp(2)
setsid(2)
tcsetpgrp(2)