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(): _XOPEN_SOURCE >= 500
23 setpgrp() (POSIX.1): _SVID_SOURCE || _XOPEN_SOURCE >= 500
24
25 setpgrp() (BSD), getpgrp() (BSD): _BSD_SOURCE && ! (_POSIX_SOURCE ||
26 _POSIX_C_SOURCE || _XOPEN_SOURCE || _XOPEN_SOURCE_EXTENDED ||
27 _GNU_SOURCE || _SVID_SOURCE)
28
30 All of these interfaces are available on Linux, and are used for get‐
31 ting and setting the process group ID (PGID) of a process. The pre‐
32 ferred, POSIX.1-specified ways of doing this are: getpgrp(void), for
33 retrieving the calling process's PGID; and setpgid(), for setting a
34 process's PGID.
35
36 setpgid() sets the PGID of the process specified by pid to pgid. If
37 pid is zero, then the process ID of the calling process is used. If
38 pgid is zero, then the PGID of the process specified by pid is made the
39 same as its process ID. If setpgid() is used to move a process from
40 one process group to another (as is done by some shells when creating
41 pipelines), both process groups must be part of the same session (see
42 setsid(2) and credentials(7)). In this case, the pgid specifies an
43 existing process group to be joined and the session ID of that group
44 must match the session ID of the joining process.
45
46 The POSIX.1 version of getpgrp(), which takes no arguments, returns the
47 PGID of the calling process.
48
49 getpgid() returns the PGID of the process specified by pid. If pid is
50 zero, the process ID of the calling process is used. (Retrieving the
51 PGID of a process other than the caller is rarely necessary, and the
52 POSIX.1 getpgrp() is preferred for that task.)
53
54 The System V-style setpgrp(), which takes no arguments, is equivalent
55 to setpgid(0, 0).
56
57 The BSD-specific setpgrp() call, which takes arguments pid and pgid, is
58 equivalent to setpgid(pid, pgid).
59
60 The BSD-specific getpgrp() call, which takes a single pid argument, is
61 equivalent to getpgid(pid).
62
64 On success, setpgid() and setpgrp() return zero. On error, -1 is
65 returned, and errno is set appropriately.
66
67 The POSIX.1 getpgrp() always returns the PGID of the caller.
68
69 getpgid(), and the BSD-specific getpgrp() return a process group on
70 success. On error, -1 is returned, and errno is set appropriately.
71
73 EACCES An attempt was made to change the process group ID of one of the
74 children of the calling process and the child had already per‐
75 formed an execve(2) (setpgid(), setpgrp()).
76
77 EINVAL pgid is less than 0 (setpgid(), setpgrp()).
78
79 EPERM An attempt was made to move a process into a process group in a