1SETPGID(2) Linux Programmer's Manual SETPGID(2)
2
3
4
6 setpgid, getpgid, setpgrp, getpgrp - set/get process group
7
9 #include <unistd.h>
10
11 int setpgid(pid_t pid, pid_t pgid);
12 pid_t getpgid(pid_t pid);
13
14 pid_t getpgrp(void); /* POSIX.1 version */
15 pid_t getpgrp(pid_t pid); /* BSD version */
16
17 int setpgrp(void); /* System V version */
18 int setpgrp(pid_t pid, pid_t pgid); /* BSD version */
19
20 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22 getpgid():
23 _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
24 || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
25
26 setpgrp() (POSIX.1):
27 _SVID_SOURCE || _XOPEN_SOURCE >= 500 ||
28 _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
29
30 setpgrp() (BSD), getpgrp() (BSD):
31 _BSD_SOURCE &&
32 ! (_POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE ||
33 _XOPEN_SOURCE_EXTENDED || _GNU_SOURCE || _SVID_SOURCE)
34
36 All of these interfaces are available on Linux, and are used for get‐
37 ting and setting the process group ID (PGID) of a process. The pre‐
38 ferred, POSIX.1-specified ways of doing this are: getpgrp(void), for
39 retrieving the calling process's PGID; and setpgid(), for setting a
40 process's PGID.
41
42 setpgid() sets the PGID of the process specified by pid to pgid. If
43 pid is zero, then the process ID of the calling process is used. If
44 pgid is zero, then the PGID of the process specified by pid is made the
45 same as its process ID. If setpgid() is used to move a process from
46 one process group to another (as is done by some shells when creating
47 pipelines), both process groups must be part of the same session (see
48 setsid(2) and credentials(7)). In this case, the pgid specifies an
49 existing process group to be joined and the session ID of that group
50 must match the session ID of the joining process.
51
52 The POSIX.1 version of getpgrp(), which takes no arguments, returns the
53 PGID of the calling process.
54
55 getpgid() returns the PGID of the process specified by pid. If pid is
56 zero, the process ID of the calling process is used. (Retrieving the
57 PGID of a process other than the caller is rarely necessary, and the
58 POSIX.1 getpgrp() is preferred for that task.)
59
60 The System V-style setpgrp(), which takes no arguments, is equivalent
61 to setpgid(0, 0).
62
63 The BSD-specific setpgrp() call, which takes arguments pid and pgid, is
64 equivalent to setpgid(pid, pgid).
65
66 The BSD-specific getpgrp() call, which takes a single pid argument, is
67 equivalent to getpgid(pid).
68
70 On success, setpgid() and setpgrp() return zero. On error, -1 is
71 returned, and errno is set appropriately.
72
73 The POSIX.1 getpgrp() always returns the PGID of the caller.
74
75 getpgid(), and the BSD-specific getpgrp() return a process group on
76 success. On error, -1 is returned, and errno is set appropriately.
77
79 EACCES An attempt was made to change the process group ID of one of the
80 children of the calling process and the child had already per‐