]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/credentials.7
execve.2: Some tweaks to Shawn Landden's patch
[thirdparty/man-pages.git] / man7 / credentials.7
CommitLineData
c11b1abf 1.\" Copyright (c) 2007 by Michael Kerrisk <mtk.manpages@gmail.com>
8e5a067a 2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
8e5a067a
MK
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.
7.\"
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.
12.\"
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
10d76543
MK
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
19.\" professionally.
8e5a067a
MK
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
8e5a067a
MK
24.\"
25.\" 2007-06-13 Creation
26.\"
35deeb87 27.TH CREDENTIALS 7 2016-12-12 "Linux" "Linux Programmer's Manual"
8e5a067a
MK
28.SH NAME
29credentials \- process identifiers
30.SH DESCRIPTION
31.SS Process ID (PID)
2fda57bd 32Each process has a unique nonnegative integer identifier
8e5a067a
MK
33that is assigned when the process is created using
34.BR fork (2).
35A process can obtain its PID using
36.BR getpid (2).
37A PID is represented using the type
0daa9e92 38.I pid_t
8e5a067a
MK
39(defined in
40.IR <sys/types.h> ).
a721e8b2 41.PP
8e5a067a
MK
42PIDs are used in a range of system calls to identify the process
43affected by the call, for example:
44.BR kill (2),
45.BR ptrace (2),
46.BR setpriority (2)
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),
54.BR setpgid (2),
55.\" .BR getsid (2),
56.BR setsid (2),
485ab701 57.BR sigqueue (3),
8e5a067a
MK
58and
59.BR waitpid (2).
60.\" .BR waitid (2),
61.\" .BR wait4 (2),
a721e8b2 62.PP
8e5a067a
MK
63A process's PID is preserved across an
64.BR execve (2).
c634028a 65.SS Parent process ID (PPID)
cfadad46 66A process's parent process ID identifies the process that created
8e5a067a
MK
67this process using
68.BR fork (2).
69A process can obtain its PPID using
70.BR getppid (2).
71A PPID is represented using the type
72.IR pid_t .
a721e8b2 73.PP
8e5a067a
MK
74A process's PPID is preserved across an
75.BR execve (2).
c634028a 76.SS Process group ID and session ID
8e5a067a
MK
77Each process has a session ID and a process group ID,
78both represented using the type
79.IR pid_t .
988db661 80A process can obtain its session ID using
36b91932 81.BR getsid (2),
8e5a067a
MK
82and its process group ID using
83.BR getpgrp (2).
a721e8b2 84.PP
8e5a067a
MK
85A child created by
86.BR fork (2)
87inherits its parent's session ID and process group ID.
88A process's session ID and process group ID are preserved across an
89.BR execve (2).
a721e8b2 90.PP
8e5a067a
MK
91Sessions and process groups are abstractions devised to support shell
92job control.
988db661 93A process group (sometimes called a "job") is a collection of
8e5a067a
MK
94processes that share the same process group ID;
95the shell creates a new process group for the process(es) used
96to execute single command or pipeline (e.g., the two processes
97created to execute the command "ls\ |\ wc" are placed in the
98same process group).
99A process's group membership can be set using
100.BR setpgid (2).
101The process whose process ID is the same as its process group ID is the
102\fIprocess group leader\fP for that group.
a721e8b2 103.PP
8e5a067a
MK
104A session is a collection of processes that share the same session ID.
105All 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
107same session, so that sessions and process groups form a strict
108two-level hierarchy of processes.)
109A new session is created when a process calls
110.BR setsid (2),
111which creates a new session whose session ID is the same
112as the PID of the process that called
113.BR setsid (2).
114The creator of the session is called the \fIsession leader\fP.
a721e8b2 115.PP
eb4df3a0
MK
116All of the processes in a session share a
117.IR "controlling terminal" .
118The controlling terminal is established when the session leader
119first opens a terminal (unless the
120.BR O_NOCTTY
121flag is specified when calling
122.BR open (2)).
123A terminal may be the controlling terminal of at most one session.
a721e8b2 124.PP
eb4df3a0
MK
125At most one of the jobs in a session may be the
126.IR "foreground job" ;
127other jobs in the session are
128.IR "background jobs" .
129Only the foreground job may read from the terminal;
130when a process in the background attempts to read from the terminal,
131its process group is sent a
132.BR SIGTTIN
133signal, which suspends the job.
134If the
135.BR TOSTOP
136flag has been set for the terminal (see
137.BR termios (3)),
138then only the foreground job may write to the terminal;
139writes from background job cause a
140.BR SIGTTOU
141signal to be generated, which suspends the job.
142When terminal keys that generate a signal (such as the
143.I interrupt
144key, normally control-C)
145are pressed, the signal is sent to the processes in the foreground job.
a721e8b2 146.PP
d3532647 147Various system calls and library functions
299eee50
MK
148may operate on all members of a process group,
149including
150.BR kill (2),
498aad50 151.BR killpg (3),
299eee50
MK
152.BR getpriority (2),
153.BR setpriority (2),
154.BR ioprio_get (2),
155.BR ioprio_set (2),
156.BR waitid (2),
157and
158.BR waitpid (2).
159See also the discussion of the
160.BR F_GETOWN ,
161.BR F_GETOWN_EX ,
162.BR F_SETOWN ,
163and
164.BR F_SETOWN_EX
165operations in
166.BR fcntl (2).
c634028a 167.SS User and group identifiers
69b24321 168Each process has various associated user and group IDs.
8e5a067a
MK
169These IDs are integers, respectively represented using the types
170.I uid_t
171and
0daa9e92 172.I gid_t
8e5a067a
MK
173(defined in
174.IR <sys/types.h> ).
a721e8b2 175.PP
8e5a067a
MK
176On Linux, each process has the following user and group identifiers:
177.IP * 3
178Real user ID and real group ID.
179These IDs determine who owns the process.
180A process can obtain its real user (group) ID using
181.BR getuid (2)
182.RB ( getgid (2)).
183.IP *
184Effective user ID and effective group ID.
185These IDs are used by the kernel to determine the permissions
186that the process will have when accessing shared resources such
187as message queues, shared memory, and semaphores.
008f1ecc 188On most UNIX systems, these IDs also determine the
8e5a067a 189permissions when accessing files.
9ee4a2b6 190However, Linux uses the filesystem IDs described below
8e5a067a
MK
191for this task.
192A process can obtain its effective user (group) ID using
193.BR geteuid (2)
194.RB ( getegid (2)).
195.IP *
196Saved set-user-ID and saved set-group-ID.
197These IDs are used in set-user-ID and set-group-ID programs to save
198a copy of the corresponding effective IDs that were set when
199the program was executed (see
200.BR execve (2)).
201A set-user-ID program can assume and drop privileges by
202switching its effective user ID back and forth between the values
203in its real user ID and saved set-user-ID.
204This switching is done via calls to
205.BR seteuid (2),
206.BR setreuid (2),
207or
208.BR setresuid (2).
209A set-group-ID program performs the analogous tasks using
210.BR setegid (2),
211.BR setregid (2),
212or
213.BR setresgid (2).
214A process can obtain its saved set-user-ID (set-group-ID) using
215.BR getresuid (2)
216.RB ( getresgid (2)).
217.IP *
9ee4a2b6 218Filesystem user ID and filesystem group ID (Linux-specific).
8e5a067a
MK
219These IDs, in conjunction with the supplementary group IDs described
220below, are used to determine permissions for accessing files; see
221.BR path_resolution (7)
222for details.
223Whenever a process's effective user (group) ID is changed,
9ee4a2b6 224the kernel also automatically changes the filesystem user (group) ID
8e5a067a 225to the same value.
9ee4a2b6 226Consequently, the filesystem IDs normally have the same values
8e5a067a 227as the corresponding effective ID, and the semantics for file-permission
008f1ecc 228checks are thus the same on Linux as on other UNIX systems.
9ee4a2b6 229The filesystem IDs can be made to differ from the effective IDs
8e5a067a
MK
230by calling
231.BR setfsuid (2)
232and
233.BR setfsgid (2).
234.IP *
235Supplementary group IDs.
236This is a set of additional group IDs that are used for permission
237checks when accessing files and other shared resources.
238On Linux kernels before 2.6.4,
239a process can be a member of up to 32 supplementary groups;
240since kernel 2.6.4,
241a process can be a member of up to 65536 supplementary groups.
b15f3638
MK
242The call
243.I sysconf(_SC_NGROUPS_MAX)
244can be used to determine the number of supplementary groups
245of which a process may be a member.
8e5a067a
MK
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.
249A process can obtain its set of supplementary group IDs using
6c4bd3ed 250.BR getgroups (2),
8e5a067a
MK
251and can modify the set using
252.BR setgroups (2).
253.PP
254A child process created by
255.BR fork (2)
256inherits copies of its parent's user and groups IDs.
257During an
258.BR execve (2),
988db661 259a process's real user and group ID and supplementary
8e5a067a
MK
260group IDs are preserved;
261the effective and saved set IDs may be changed, as described in
262.BR execve (2).
a721e8b2 263.PP
8e5a067a
MK
264Aside from the purposes noted above,
265a process's user IDs are also employed in a number of other contexts:
266.IP * 3
bf263379
MK
267when determining the permissions for sending signals (see
268.BR kill (2));
8e5a067a
MK
269.IP *
270when determining the permissions for setting
988db661 271process-scheduling parameters (nice value, real time
8e5a067a
MK
272scheduling policy and priority, CPU affinity, I/O priority) using
273.BR setpriority (2),
274.BR sched_setaffinity (2),
275.BR sched_setscheduler (2),
276.BR sched_setparam (2),
283d0def 277.BR sched_setattr (2),
8e5a067a
MK
278and
279.BR ioprio_set (2);
280.IP *
bf263379
MK
281when checking resource limits (see
282.BR getrlimit (2));
8e5a067a
MK
283.IP *
284when checking the limit on the number of inotify instances
bf263379
MK
285that the process may create (see
286.BR inotify (7)).
47297adb 287.SH CONFORMING TO
0034a22b 288Process IDs, parent process IDs, process group IDs, and session IDs
eedfc430 289are specified in POSIX.1.
f8850a38 290The real, effective, and saved set user and groups IDs,
eedfc430 291and the supplementary group IDs, are specified in POSIX.1.
9ee4a2b6 292The filesystem user and group IDs are a Linux extension.
8e5a067a 293.SH NOTES
6923f52c
MK
294The POSIX threads specification requires that
295credentials are shared by all of the threads in a process.
296However, at the kernel level, Linux maintains separate user and group
297credentials for each thread.
298The NPTL threading implementation does some work to ensure
299that any change to user or group credentials
300(e.g., calls to
301.BR setuid (2),
41fa59c0 302.BR setresuid (2))
6923f52c 303is carried through to all of the POSIX threads in a process.
2baa3e91
MK
304See
305.BR nptl (7)
306for further details.
47297adb 307.SH SEE ALSO
8e5a067a 308.BR bash (1),
f0c34053 309.BR csh (1),
bcaa9b6e 310.BR groups (1),
4d3b948c 311.BR id (1),
17fb5e56 312.BR newgrp (1),
8e5a067a 313.BR ps (1),
0b8adf96 314.BR runuser (1),
dac9acbf 315.BR setpriv (1),
127a794d
MK
316.BR sg (1),
317.BR su (1),
8e5a067a
MK
318.BR access (2),
319.BR execve (2),
320.BR faccessat (2),
321.BR fork (2),
fadd2e65 322.BR getgroups (2),
8e5a067a
MK
323.BR getpgrp (2),
324.BR getpid (2),
325.BR getppid (2),
326.BR getsid (2),
327.BR kill (2),
8e5a067a
MK
328.BR setegid (2),
329.BR seteuid (2),
330.BR setfsgid (2),
331.BR setfsuid (2),
332.BR setgid (2),
333.BR setgroups (2),
9d604ae9 334.BR setpgid (2),
8e5a067a
MK
335.BR setresgid (2),
336.BR setresuid (2),
9d604ae9 337.BR setsid (2),
8e5a067a
MK
338.BR setuid (2),
339.BR waitpid (2),
340.BR euidaccess (3),
341.BR initgroups (3),
498aad50 342.BR killpg (3),
8e5a067a 343.BR tcgetpgrp (3),
b7921eb6 344.BR tcgetsid (3),
8e5a067a 345.BR tcsetpgrp (3),
d17b32ad
MK
346.BR group (5),
347.BR passwd (5),
def79251 348.BR shadow (5),
8e5a067a 349.BR capabilities (7),
4effb5be 350.BR namespaces (7),
8e5a067a 351.BR path_resolution (7),
7e0e902b 352.BR pid_namespaces (7),
19832d3c 353.BR pthreads (7),
eb4df3a0 354.BR signal (7),
2b4be1ea 355.BR unix (7),
d17b32ad 356.BR user_namespaces (7),
2b4be1ea 357.BR sudo (8)