.\" Copyright (c) 1983, 1991 Regents of the University of California.
+.\" and Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
.\" All rights reserved.
.\"
+.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
+.\" %%%LICENSE_END
.\"
.\" @(#)getpgrp.2 6.4 (Berkeley) 3/10/91
.\"
.\" Modified 1996-07-21 by Andries Brouwer <aeb@cwi.nl>
.\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
.\" Modified 1999-09-02 by Michael Haardt <michael@moria.de>
-.\" Modified 2002-01-18 by Michael Kerrisk <mtk-manpages@gmx.net>
+.\" Modified 2002-01-18 by Michael Kerrisk <mtk.manpages@gmail.com>
.\" Modified 2003-01-20 by Andries Brouwer <aeb@cwi.nl>
.\" 2007-07-25, mtk, fairly substantial rewrites and rearrangements
.\" of text.
.\"
-.TH SETPGID 2 2007-07-26 "Linux" "Linux Programmer's Manual"
+.TH SETPGID 2 2016-03-15 "Linux" "Linux Programmer's Manual"
.SH NAME
setpgid, getpgid, setpgrp, getpgrp \- set/get process group
.SH SYNOPSIS
.br
.BI "pid_t getpgid(pid_t " pid );
.sp
-.BR "pid_t getpgrp(void);" " /* POSIX.1 version */"
+.BR "pid_t getpgrp(void);" " /* POSIX.1 version */"
.br
-.BI "pid_t getpgrp(psid_t " pid ");\ \ \ \ \ \ \ \ \ "
+.BI "pid_t getpgrp(pid_t " pid ");\ \ \ \ \ \ \ \ \ \ \ "
/* BSD version */
.sp
-.BR "int setpgrp(void);" " /* System V version */"
+.BR "int setpgrp(void);" " /* System V version */"
.br
-.BI "int setpgrp(pid_t " pid ", pid_t " pgid );
+.BI "int setpgrp(pid_t " pid ", pid_t " pgid ");\ "
/* BSD version */
.sp
.in -4n
.in
.sp
.ad l
+.PD 0
.BR getpgid ():
+.RS 4
_XOPEN_SOURCE\ >=\ 500
+.\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
.br
-.BR setpgrp ()
-(POSIX.1): _SVID_SOURCE || _XOPEN_SOURCE >= 500
+ || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
+.RE
+.sp
+.BR setpgrp "() (POSIX.1):"
+.nf
+ _XOPEN_SOURCE\ >=\ 500
+.\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
+ || /* Since glibc 2.19: */ _DEFAULT_SOURCE
+ || /* Glibc versions <= 2.19: */ _SVID_SOURCE
+.fi
.sp
.BR setpgrp "()\ (BSD),"
.BR getpgrp "()\ (BSD):"
-_BSD_SOURCE && !\ (_POSIX_SOURCE || _POSIX_C_SOURCE ||
-_XOPEN_SOURCE || _XOPEN_SOURCE_EXTENDED || _GNU_SOURCE || _SVID_SOURCE)
-.ad b
+.nf
+ [These are available only before glibc 2.19]
+ _BSD_SOURCE &&
+ !\ (_POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE ||
+ _GNU_SOURCE || _SVID_SOURCE)
+.fi
+.PD
+.ad
.SH DESCRIPTION
All of these interfaces are available on Linux,
and are used for getting and setting the
.IR pgid .
If
.I pid
-is zero, the process ID of the current process is used.
+is zero, then the process ID of the calling process is used.
If
.I pgid
-is zero, the process ID of the process specified by
+is zero, then the PGID of the process specified by
.I pid
-is used.
+is made the same as its process ID.
If
.BR setpgid ()
is used to move a process from one process
group to another (as is done by some shells when creating pipelines),
both process groups must be part of the same session (see
.BR setsid (2)
-and
+and
.BR credentials (7)).
In this case,
the \fIpgid\fP specifies an existing process group to be joined and the
.IR pid .
If
.I pid
-is zero, the process ID of the current process is used.
+is zero, the process ID of the calling process is used.
(Retrieving the PGID of a process other than the caller is rarely
necessary, and the POSIX.1
.BR getpgrp ()
is preferred for that task.)
-The System V-style
+The System\ V-style
.BR setpgrp (),
which takes no arguments, is equivalent to
.IR "setpgid(0,\ 0)" .
.I pid
and
.IR pgid ,
-is equivalent to
-.IR "setpgid(pid, pgid)" .
+is a wrapper function that calls
+
+ setpgid(pid, pgid)
+
.\" 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.
+Since glibc 2.19, the BSD-specific
+.BR setpgrp ()
+function is no longer exposed by
+.IR <unistd.h> ;
+calls should be replaced with the
+.BR setpgid ()
+call shown above.
The BSD-specific
.BR getpgrp ()
call, which takes a single
.I pid
-argument, is equivalent to
-.IR "getpgid(pid)" .
-.SH "RETURN VALUE"
+argument, is a wrapper function that calls
+
+ getpgid(pid)
+
+Since glibc 2.19, the BSD-specific
+.BR getpgrp ()
+function is no longer exposed by
+.IR <unistd.h> ;
+calls should be replaced with calls to the POSIX.1
+.BR getpgrp ()
+which takes no arguments (if the intent is to obtain the caller's PGID),
+or with the
+.BR getpgid ()
+call shown above.
+.SH RETURN VALUE
On success,
.BR setpgid ()
and
For
.BR setpgid ():
.I pid
-is not the current process and not a child of the current process.
-.SH "CONFORMING TO"
+is not the calling process and not a child of the calling process.
+.SH CONFORMING TO
.BR setpgid ()
and the version of
.BR getpgrp ()
-with no argumennts
+with no arguments
conform to POSIX.1-2001.
POSIX.1-2001 also specifies
and the version of
.BR setpgrp ()
that takes no arguments.
+(POSIX.1-2008 marks this
+.BR setpgrp ()
+specification as obsolete.)
The version of
.BR getpgrp ()
from the terminal;
if a background process group tries to
.BR read (2)
-from the terminal, then the group is send a
-.BR SIGTSTP
+from the terminal, then the group is sent a
+.B SIGTTIN
signal, which suspends it.
The
.BR tcgetpgrp (3)
.B SIGCONT
signal will be sent to each process
in the newly orphaned process group.
-.SH "SEE ALSO"
+.\" exit.3 refers to the following text:
+An orphaned process group is one in which the parent of
+every member of process group is either itself also a member
+of the process group or is a member of a process group
+in a different session (see also
+.BR credentials (7)).
+.SH SEE ALSO
.BR getuid (2),
.BR setsid (2),
.BR tcgetpgrp (3),
.BR tcsetpgrp (3),
-.BR termios (3)
+.BR termios (3),
+.BR credentials (7)