.TH setpgid() "" "" "System Call (libc)"
.PC "Set the process-group identifier"
.B "#include <sys/types.h>"
.B "#include <unistd.h>"
\fBint setpgid(\fIpid\^\fB, \fIpgid\^\fB)\fR
\fBpid_t \fIpid\^\fB, \fIpgid\^\fB;\fR
.PP
.B setpgid()
sets to
.I pgid
the process-group identifier of the process with identifier
.IR pid .
If
.I pgid
equals
.IR pid ,
the process becomes a process-group leader.
If
.I pgid
does not equal
.IR pid ,
the process becomes a member of an existing process group.
.PP
If
.I pid
equals zero,
.B setpgid()
uses the process identifier of the calling process.
If
.I pgid
equals zero, the process specified by
.I pid
becomes a process-group leader.
.PP
If all goes well,
.B setpgid()
returns a value of zero.
Otherwise, it returns \-1 and sets
.B errno
to an appropriate value.
.B setpgid()
if any of the following are true:
.IP \(bu 0.3i
.I pid
matches the process identifier of a child process of the
calling process, and that child process has successfully executed an
.B exec()
function.
.B setpgid()
sets
.B errno
to
.BR EACCES .
.IP \(bu
.I pgid
is less than zero or greater than or equal to
.BR PID_MAX .
.B setpgid()
sets
.B errno
to
.BR EINVAL .
.IP \(bu
The calling process has a controlling terminal that
does not support job control.
.B setpgid()
sets
.B errno
to
.BR EINVAL .
.IP \(bu
The process identified by
.I pid
argument is a session leader.
.B setpgid()
sets
.B errno
to
.BR EPERM .
.IP \(bu
.I pid
equals the process identifier of a child process of the
calling process, and the child process is not in the
same session as the calling process.
.B setpgid()
sets
.B errno
to
.BR EPERM .
.IP \(bu
.I pgid
does not match the process identifier of the process indicated by
.IR pid ,
and the call process's session
has no process with a process-group identifier that equals
.IR pgid .
.B setpgid()
sets
.B errno
to
.BR EPERM .
.IP \(bu
.I pid
does not match the process identifier of the calling
process or of a child process of the calling process.
.B setpgid()
sets
.B errno
to
.BR ESRCH .
.SH "See Also"
.Xr "libc," libc
.Xr "unistd.h" unistd.h
.br
\*(PX Standard, \(sc4.3.3
