1 .\" Copyright (c) 2007 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" 2007-06-13 Creation
27 .TH CREDENTIALS 7 2020-11-01 "Linux" "Linux Programmer's Manual"
29 credentials \- process identifiers
32 Each process has a unique nonnegative integer identifier
33 that is assigned when the process is created using
35 A process can obtain its PID using
37 A PID is represented using the type
42 PIDs are used in a range of system calls to identify the process
43 affected by the call, for example:
47 .\" .BR sched_rr_get_interval (2),
48 .\" .BR sched_getaffinity (2),
49 .\" .BR sched_setaffinity (2),
50 .\" .BR sched_getparam (2),
51 .\" .BR sched_setparam (2),
52 .\" .BR sched_setscheduler (2),
53 .\" .BR sched_getscheduler (2),
63 A process's PID is preserved across an
65 .SS Parent process ID (PPID)
66 A process's parent process ID identifies the process that created
69 A process can obtain its PPID using
71 A PPID is represented using the type
74 A process's PPID is preserved across an
76 .SS Process group ID and session ID
77 Each process has a session ID and a process group ID,
78 both represented using the type
80 A process can obtain its session ID using
82 and its process group ID using
87 inherits its parent's session ID and process group ID.
88 A process's session ID and process group ID are preserved across an
91 Sessions and process groups are abstractions devised to support shell
93 A process group (sometimes called a "job") is a collection of
94 processes that share the same process group ID;
95 the shell creates a new process group for the process(es) used
96 to execute single command or pipeline (e.g., the two processes
97 created to execute the command "ls\ |\ wc" are placed in the
99 A process's group membership can be set using
101 The process whose process ID is the same as its process group ID is the
102 \fIprocess group leader\fP for that group.
104 A session is a collection of processes that share the same session ID.
105 All of the members of a process group also have the same session ID
106 (i.e., all of the members of a process group always belong to the
107 same session, so that sessions and process groups form a strict
108 two-level hierarchy of processes.)
109 A new session is created when a process calls
111 which creates a new session whose session ID is the same
112 as the PID of the process that called
114 The creator of the session is called the \fIsession leader\fP.
116 All of the processes in a session share a
117 .IR "controlling terminal" .
118 The controlling terminal is established when the session leader
119 first opens a terminal (unless the
121 flag is specified when calling
123 A terminal may be the controlling terminal of at most one session.
125 At most one of the jobs in a session may be the
126 .IR "foreground job" ;
127 other jobs in the session are
128 .IR "background jobs" .
129 Only the foreground job may read from the terminal;
130 when a process in the background attempts to read from the terminal,
131 its process group is sent a
133 signal, which suspends the job.
136 flag has been set for the terminal (see
138 then only the foreground job may write to the terminal;
139 writes from background job cause a
141 signal to be generated, which suspends the job.
142 When terminal keys that generate a signal (such as the
144 key, normally control-C)
145 are pressed, the signal is sent to the processes in the foreground job.
147 Various system calls and library functions
148 may operate on all members of a process group,
159 See also the discussion of the
167 .SS User and group identifiers
168 Each process has various associated user and group IDs.
169 These IDs are integers, respectively represented using the types
176 On Linux, each process has the following user and group identifiers:
178 Real user ID and real group ID.
179 These IDs determine who owns the process.
180 A process can obtain its real user (group) ID using
184 Effective user ID and effective group ID.
185 These IDs are used by the kernel to determine the permissions
186 that the process will have when accessing shared resources such
187 as message queues, shared memory, and semaphores.
188 On most UNIX systems, these IDs also determine the
189 permissions when accessing files.
190 However, Linux uses the filesystem IDs described below
192 A process can obtain its effective user (group) ID using
196 Saved set-user-ID and saved set-group-ID.
197 These IDs are used in set-user-ID and set-group-ID programs to save
198 a copy of the corresponding effective IDs that were set when
199 the program was executed (see
201 A set-user-ID program can assume and drop privileges by
202 switching its effective user ID back and forth between the values
203 in its real user ID and saved set-user-ID.
204 This switching is done via calls to
209 A set-group-ID program performs the analogous tasks using
214 A process can obtain its saved set-user-ID (set-group-ID) using
216 .RB ( getresgid (2)).
218 Filesystem user ID and filesystem group ID (Linux-specific).
219 These IDs, in conjunction with the supplementary group IDs described
220 below, are used to determine permissions for accessing files; see
221 .BR path_resolution (7)
223 Whenever a process's effective user (group) ID is changed,
224 the kernel also automatically changes the filesystem user (group) ID
226 Consequently, the filesystem IDs normally have the same values
227 as the corresponding effective ID, and the semantics for file-permission
228 checks are thus the same on Linux as on other UNIX systems.
229 The filesystem IDs can be made to differ from the effective IDs
235 Supplementary group IDs.
236 This is a set of additional group IDs that are used for permission
237 checks when accessing files and other shared resources.
238 On Linux kernels before 2.6.4,
239 a process can be a member of up to 32 supplementary groups;
241 a process can be a member of up to 65536 supplementary groups.
243 .I sysconf(_SC_NGROUPS_MAX)
244 can be used to determine the number of supplementary groups
245 of which a process may be a member.
246 .\" Since kernel 2.6.4, the limit is visible via the read-only file
247 .\" /proc/sys/kernel/ngroups_max.
248 .\" As at 2.6.22-rc2, this file is still read-only.
249 A process can obtain its set of supplementary group IDs using
252 A child process created by
254 inherits copies of its parent's user and groups IDs.
257 a process's real user and group ID and supplementary
258 group IDs are preserved;
259 the effective and saved set IDs may be changed, as described in
262 Aside from the purposes noted above,
263 a process's user IDs are also employed in a number of other contexts:
265 when determining the permissions for sending signals (see
268 when determining the permissions for setting
269 process-scheduling parameters (nice value, real time
270 scheduling policy and priority, CPU affinity, I/O priority) using
272 .BR sched_setaffinity (2),
273 .BR sched_setscheduler (2),
274 .BR sched_setparam (2),
275 .BR sched_setattr (2),
279 when checking resource limits (see
282 when checking the limit on the number of inotify instances
283 that the process may create (see
286 .SS Modifying process user and group IDs
287 Subject to rules described in the relevant manual pages,
288 a process can use the following APIs to modify its user and group IDs:
290 .BR setuid "(2) (" setgid (2))
291 Modify the process's real (and possibly effective and saved-set)
294 .BR seteuid "(2) (" setegid (2))
295 Modify the process's effective user (group) ID.
297 .BR setfsuid "(2) (" setfsgid (2))
298 Modify the process's filesystem user (group) ID.
300 .BR setreuid "(2) (" setregid (2))
301 Modify the process's real and effective (and possibly saved-set)
304 .BR setresuid "(2) (" setresgid (2))
305 Modify the process's real, effective, and saved-set user (group) IDs.
308 Modify the process's supplementary group list.
310 Any changes to a process's effective user (group) ID
311 are automatically carried over to the process's
312 filesystem user (group) ID.
313 Changes to a process's effective user or group ID can also affect the
314 process "dumpable" attribute, as described in
317 Changes to process user and group IDs can affect the capabilities
318 of the process, as described in
319 .BR capabilities (7).
321 Process IDs, parent process IDs, process group IDs, and session IDs
322 are specified in POSIX.1.
323 The real, effective, and saved set user and groups IDs,
324 and the supplementary group IDs, are specified in POSIX.1.
325 The filesystem user and group IDs are a Linux extension.
327 Various fields in the
328 .IR /proc/[pid]/status
329 file show the process credentials described above.
332 for further information.
334 The POSIX threads specification requires that
335 credentials are shared by all of the threads in a process.
336 However, at the kernel level, Linux maintains separate user and group
337 credentials for each thread.
338 The NPTL threading implementation does some work to ensure
339 that any change to user or group credentials
343 is carried through to all of the POSIX threads in a process.
389 .BR capabilities (7),
391 .BR path_resolution (7),
392 .BR pid_namespaces (7),
395 .BR system_data_types (7),
397 .BR user_namespaces (7),