1SETPGID(2)                 Linux Programmer's Manual                SETPGID(2)
2
3
4

NAME

6       setpgid, getpgid, setpgrp, getpgrp - set/get process group
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <unistd.h>
11
12       int setpgid(pid_t pid, pid_t pgid);
13       pid_t getpgid(pid_t pid);
14
15       pid_t getpgrp(void);                 /* POSIX.1 version */
16       pid_t getpgrp(pid_t pid);            /* BSD version */
17
18       int setpgrp(void);                   /* System V version */
19       int setpgrp(pid_t pid, pid_t pgid);  /* BSD version */
20
21   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
22
23       getpgid():
24           _XOPEN_SOURCE >= 500
25               || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
26
27       setpgrp() (POSIX.1):
28           _XOPEN_SOURCE >= 500
29               || /* Since glibc 2.19: */ _DEFAULT_SOURCE
30               || /* Glibc versions <= 2.19: */ _SVID_SOURCE
31
32       setpgrp() (BSD), getpgrp() (BSD):
33           [These are available only before glibc 2.19]
34           _BSD_SOURCE &&
35               ! (_POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE ||
36                   _GNU_SOURCE || _SVID_SOURCE)
37

DESCRIPTION

39       All  of  these interfaces are available on Linux, and are used for get‐
40       ting and setting the process group ID (PGID) of a  process.   The  pre‐
41       ferred,  POSIX.1-specified  ways  of doing this are: getpgrp(void), for
42       retrieving the calling process's PGID; and  setpgid(),  for  setting  a
43       process's PGID.
44
45       setpgid()  sets  the  PGID of the process specified by pid to pgid.  If
46       pid is zero, then the process ID of the calling process  is  used.   If
47       pgid is zero, then the PGID of the process specified by pid is made the
48       same as its process ID.  If setpgid() is used to move  a  process  from
49       one  process  group to another (as is done by some shells when creating
50       pipelines), both process groups must be part of the same  session  (see
51       setsid(2) and credentials(7)).  In this case, the pgid specifies an ex‐
52       isting process group to be joined and the session ID of that group must
53       match the session ID of the joining process.
54
55       The POSIX.1 version of getpgrp(), which takes no arguments, returns the
56       PGID of the calling process.
57
58       getpgid() returns the PGID of the process specified by pid.  If pid  is
59       zero,  the  process ID of the calling process is used.  (Retrieving the
60       PGID of a process other than the caller is rarely  necessary,  and  the
61       POSIX.1 getpgrp() is preferred for that task.)
62
63       The  System V-style  setpgrp(), which takes no arguments, is equivalent
64       to setpgid(0, 0).
65
66       The BSD-specific setpgrp() call, which takes arguments pid and pgid, is
67       a wrapper function that calls
68
69           setpgid(pid, pgid)
70
71       Since  glibc 2.19, the BSD-specific setpgrp() function is no longer ex‐
72       posed by <unistd.h>; calls should be replaced with the  setpgid()  call
73       shown above.
74
75       The  BSD-specific getpgrp() call, which takes a single pid argument, is
76       a wrapper function that calls
77
78           getpgid(pid)
79
80       Since glibc 2.19, the BSD-specific getpgrp() function is no longer  ex‐
81       posed by <unistd.h>; calls should be replaced with calls to the POSIX.1
82       getpgrp() which takes no arguments (if the  intent  is  to  obtain  the
83       caller's PGID)