1 .\" Copyright (c) 1983, 1991 Regents of the University of California.
2 .\" and Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" @(#)getpgrp.2 6.4 (Berkeley) 3/10/91
35 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
36 .\" Modified 1995-04-15 by Michael Chastain <mec@shell.portal.com>:
38 .\" Modified 1996-07-21 by Andries Brouwer <aeb@cwi.nl>
39 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
40 .\" Modified 1999-09-02 by Michael Haardt <michael@moria.de>
41 .\" Modified 2002-01-18 by Michael Kerrisk <mtk.manpages@gmail.com>
42 .\" Modified 2003-01-20 by Andries Brouwer <aeb@cwi.nl>
43 .\" 2007-07-25, mtk, fairly substantial rewrites and rearrangements
46 .TH SETPGID 2 2009-09-20 "Linux" "Linux Programmer's Manual"
48 setpgid, getpgid, setpgrp, getpgrp \- set/get process group
50 .B #include <unistd.h>
52 .BI "int setpgid(pid_t " pid ", pid_t " pgid );
54 .BI "pid_t getpgid(pid_t " pid );
56 .BR "pid_t getpgrp(void);" " /* POSIX.1 version */"
58 .BI "pid_t getpgrp(pid_t " pid ");\ \ \ \ \ \ \ \ \ "
61 .BR "int setpgrp(void);" " /* System V version */"
63 .BI "int setpgrp(pid_t " pid ", pid_t " pgid );
67 Feature Test Macro Requirements for glibc (see
68 .BR feature_test_macros (7)):
73 _XOPEN_SOURCE\ >=\ 500
76 (POSIX.1): _SVID_SOURCE || _XOPEN_SOURCE >= 500
78 .BR setpgrp "()\ (BSD),"
79 .BR getpgrp "()\ (BSD):"
80 _BSD_SOURCE && !\ (_POSIX_SOURCE || _POSIX_C_SOURCE ||
81 _XOPEN_SOURCE || _XOPEN_SOURCE_EXTENDED || _GNU_SOURCE || _SVID_SOURCE)
84 All of these interfaces are available on Linux,
85 and are used for getting and setting the
86 process group ID (PGID) of a process.
87 The preferred, POSIX.1-specified ways of doing this are:
89 for retrieving the calling process's PGID; and
91 for setting a process's PGID.
94 sets the PGID of the process specified by
100 is zero, then the process ID of the calling process is used.
103 is zero, then the PGID of the process specified by
105 is made the same as its process ID.
108 is used to move a process from one process
109 group to another (as is done by some shells when creating pipelines),
110 both process groups must be part of the same session (see
113 .BR credentials (7)).
115 the \fIpgid\fP specifies an existing process group to be joined and the
116 session ID of that group must match the session ID of the joining process.
118 The POSIX.1 version of
120 which takes no arguments,
121 returns the PGID of the calling process.
124 returns the PGID of the process specified by
128 is zero, the process ID of the calling process is used.
129 (Retrieving the PGID of a process other than the caller is rarely
130 necessary, and the POSIX.1
132 is preferred for that task.)
136 which takes no arguments, is equivalent to
137 .IR "setpgid(0,\ 0)" .
141 call, which takes arguments
146 .IR "setpgid(pid, pgid)" .
147 .\" The true BSD setpgrp() system call differs in allowing the PGID
148 .\" to be set to arbitrary values, rather than being restricted to
149 .\" PGIDs in the same session.
153 call, which takes a single
155 argument, is equivalent to
163 On error, \-1 is returned, and
165 is set appropriately.
169 always returns the PGID of the caller.
174 return a process group on success.
175 On error, \-1 is returned, and
177 is set appropriately.
181 An attempt was made to change the process group ID
182 of one of the children of the calling process and the child had
195 An attempt was made to move a process into a process group in a
196 different session, or to change the process
197 group ID of one of the children of the calling process and the
198 child was in a different session, or to change the process group ID of
207 does not match any process.
211 is not the calling process and not a child of the calling process.
217 conform to POSIX.1-2001.
219 POSIX.1-2001 also specifies
223 that takes no arguments.
224 (POSIX.1-2008 marks this
226 specification as obsolete.)
230 with one argument and the version of
232 that takes two arguments derive from 4.2BSD,
233 and are not specified by POSIX.1.
237 inherits its parent's process group ID.
238 The PGID is preserved across an
241 Each process group is a member of a session and each process is a
242 member of the session of which its process group is a member.
244 A session can have a controlling terminal.
245 At any time, one (and only one) of the process groups
246 in the session can be the foreground process group
248 the remaining process groups are in the background.
249 If a signal is generated from the terminal (e.g., typing the
250 interrupt key to generate
252 that signal is sent to the foreground process group.
255 for a description of the characters that generate signals.)
256 Only the foreground process group may
259 if a background process group tries to
261 from the terminal, then the group is sent a
263 signal, which suspends it.
268 functions are used to get/set the foreground
269 process group of the controlling terminal.
275 calls are used by programs such as
277 to create process groups in order to implement shell job control.
279 If a session has a controlling terminal, and the
281 flag for that terminal is not set,
282 and a terminal hangup occurs, then the session leader is sent a
284 If the session leader exits, then a
286 signal will also be sent to each process in the foreground
287 process group of the controlling terminal.
289 If the exit of the process causes a process group to become orphaned,
290 and if any member of the newly orphaned process group is stopped, then a
294 signal will be sent to each process
295 in the newly orphaned process group.
296 .\" exit.3 refers to the following text:
297 An orphaned process group is one in which the parent of
298 every member of process group is either itself also a member
299 of the process group or is a member of a process group
300 in a different session (see also
301 .BR credentials (7)).