.\" 2007-07-25, mtk, fairly substantial rewrites and rearrangements
.\" of text.
.\"
-.TH SETPGID 2 2016-03-15 "Linux" "Linux Programmer's Manual"
+.TH SETPGID 2 2017-09-15 "Linux" "Linux Programmer's Manual"
.SH NAME
setpgid, getpgid, setpgrp, getpgrp \- set/get process group
.SH SYNOPSIS
+.B #include <sys/types.h>
+.br
.B #include <unistd.h>
-.sp
+.PP
.BI "int setpgid(pid_t " pid ", pid_t " pgid );
.br
.BI "pid_t getpgid(pid_t " pid );
-.sp
+.PP
.BR "pid_t getpgrp(void);" " /* POSIX.1 version */"
.br
.BI "pid_t getpgrp(pid_t " pid ");\ \ \ \ \ \ \ \ \ \ \ "
/* BSD version */
-.sp
+.PP
.BR "int setpgrp(void);" " /* System V version */"
.br
.BI "int setpgrp(pid_t " pid ", pid_t " pgid ");\ "
/* BSD version */
-.sp
+.PP
.in -4n
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.in
-.sp
+.PP
.ad l
-.PD 0
.BR getpgid ():
.RS 4
_XOPEN_SOURCE\ >=\ 500
.br
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
.RE
-.sp
+.PP
.BR setpgrp "() (POSIX.1):"
.nf
_XOPEN_SOURCE\ >=\ 500
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE
|| /* Glibc versions <= 2.19: */ _SVID_SOURCE
.fi
-.sp
+.PP
.BR setpgrp "()\ (BSD),"
.BR getpgrp "()\ (BSD):"
.nf
!\ (_POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE ||
_GNU_SOURCE || _SVID_SOURCE)
.fi
-.PD
.ad
.SH DESCRIPTION
All of these interfaces are available on Linux,
for retrieving the calling process's PGID; and
.BR setpgid (),
for setting a process's PGID.
-
+.PP
.BR setpgid ()
sets the PGID of the process specified by
.I pid
In this case,
the \fIpgid\fP specifies an existing process group to be joined and the
session ID of that group must match the session ID of the joining process.
-
+.PP
The POSIX.1 version of
.BR getpgrp (),
which takes no arguments,
returns the PGID of the calling process.
-
+.PP
.BR getpgid ()
returns the PGID of the process specified by
.IR pid .
necessary, and the POSIX.1
.BR getpgrp ()
is preferred for that task.)
-
+.PP
The System\ V-style
.BR setpgrp (),
which takes no arguments, is equivalent to
.IR "setpgid(0,\ 0)" .
-
+.PP
The BSD-specific
.BR setpgrp ()
call, which takes arguments
and
.IR pgid ,
is a wrapper function that calls
-
+.PP
setpgid(pid, pgid)
-
+.PP
.\" The true BSD setpgrp() system call differs in allowing the PGID
.\" to be set to arbitrary values, rather than being restricted to
.\" PGIDs in the same session.
calls should be replaced with the
.BR setpgid ()
call shown above.
-
+.PP
The BSD-specific
.BR getpgrp ()
call, which takes a single
.I pid
argument, is a wrapper function that calls
-
+.PP
getpgid(pid)
-
+.PP
Since glibc 2.19, the BSD-specific
.BR getpgrp ()
function is no longer exposed by
On error, \-1 is returned, and
.I errno
is set appropriately.
-
+.PP
The POSIX.1
.BR getpgrp ()
always returns the PGID of the caller.
-
+.PP
.BR getpgid (),
and the BSD-specific
.BR getpgrp ()
.BR getpgrp ()
with no arguments
conform to POSIX.1-2001.
-
+.PP
POSIX.1-2001 also specifies
.BR getpgid ()
and the version of
(POSIX.1-2008 marks this
.BR setpgrp ()
specification as obsolete.)
-
+.PP
The version of
.BR getpgrp ()
with one argument and the version of
inherits its parent's process group ID.
The PGID is preserved across an
.BR execve (2).
-
+.PP
Each process group is a member of a session and each process is a
member of the session of which its process group is a member.
(See
.BR credentials (7).)
-
+.PP
A session can have a controlling terminal.
At any time, one (and only one) of the process groups
in the session can be the foreground process group
.BR tcsetpgrp (3)
functions are used to get/set the foreground
process group of the controlling terminal.
-
+.PP
The
.BR setpgid ()
and
calls are used by programs such as
.BR bash (1)
to create process groups in order to implement shell job control.
-
+.PP
If the termination of a process causes a process group to become orphaned,
and if any member of the newly orphaned process group is stopped, then a
.B SIGHUP