OSDN Git Service

(split) LDP: Update original to LDP v3.54
[linuxjm/LDP_man-pages.git] / original / man7 / credentials.7
1 .\" Copyright (c) 2007 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
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
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" 2007-06-13 Creation
26 .\"
27 .TH CREDENTIALS 7 2008-06-03 "Linux" "Linux Programmer's Manual"
28 .SH NAME
29 credentials \- process identifiers
30 .SH DESCRIPTION
31 .SS Process ID (PID)
32 Each process has a unique nonnegative integer identifier
33 that is assigned when the process is created using
34 .BR fork (2).
35 A process can obtain its PID using
36 .BR getpid (2).
37 A PID is represented using the type
38 .I pid_t
39 (defined in
40 .IR <sys/types.h> ).
41
42 PIDs are used in a range of system calls to identify the process
43 affected 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),
57 .BR sigqueue (3),
58 and
59 .BR waitpid (2).
60 .\" .BR waitid (2),
61 .\" .BR wait4 (2),
62
63 A process's PID is preserved across an
64 .BR execve (2).
65 .SS Parent process ID (PPID)
66 A process's parent process ID identifies the process that created
67 this process using
68 .BR fork (2).
69 A process can obtain its PPID using
70 .BR getppid (2).
71 A PPID is represented using the type
72 .IR pid_t .
73
74 A process's PPID is preserved across an
75 .BR execve (2).
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
79 .IR pid_t .
80 A process can obtain its session ID using
81 .BR getsid (2),
82 and its process group ID using
83 .BR getpgrp (2).
84
85 A child created by
86 .BR fork (2)
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
89 .BR execve (2).
90
91 Sessions and process groups are abstractions devised to support shell
92 job control.
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
98 same process group).
99 A process's group membership can be set using
100 .BR setpgid (2).
101 The process whose process ID is the same as its process group ID is the
102 \fIprocess group leader\fP for that group.
103
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
110 .BR setsid (2),
111 which creates a new session whose session ID is the same
112 as the PID of the process that called
113 .BR setsid (2).
114 The creator of the session is called the \fIsession leader\fP.
115 .SS User and group identifiers
116 Each process has various associated user and groups IDs.
117 These IDs are integers, respectively represented using the types
118 .I uid_t
119 and
120 .I gid_t
121 (defined in
122 .IR <sys/types.h> ).
123
124 On Linux, each process has the following user and group identifiers:
125 .IP * 3
126 Real user ID and real group ID.
127 These IDs determine who owns the process.
128 A process can obtain its real user (group) ID using
129 .BR getuid (2)
130 .RB ( getgid (2)).
131 .IP *
132 Effective user ID and effective group ID.
133 These IDs are used by the kernel to determine the permissions
134 that the process will have when accessing shared resources such
135 as message queues, shared memory, and semaphores.
136 On most UNIX systems, these IDs also determine the
137 permissions when accessing files.
138 However, Linux uses the filesystem IDs described below
139 for this task.
140 A process can obtain its effective user (group) ID using
141 .BR geteuid (2)
142 .RB ( getegid (2)).
143 .IP *
144 Saved set-user-ID and saved set-group-ID.
145 These IDs are used in set-user-ID and set-group-ID programs to save
146 a copy of the corresponding effective IDs that were set when
147 the program was executed (see
148 .BR execve (2)).
149 A set-user-ID program can assume and drop privileges by
150 switching its effective user ID back and forth between the values
151 in its real user ID and saved set-user-ID.
152 This switching is done via calls to
153 .BR seteuid (2),
154 .BR setreuid (2),
155 or
156 .BR setresuid (2).
157 A set-group-ID program performs the analogous tasks using
158 .BR setegid (2),
159 .BR setregid (2),
160 or
161 .BR setresgid (2).
162 A process can obtain its saved set-user-ID (set-group-ID) using
163 .BR getresuid (2)
164 .RB ( getresgid (2)).
165 .IP *
166 Filesystem user ID and filesystem group ID (Linux-specific).
167 These IDs, in conjunction with the supplementary group IDs described
168 below, are used to determine permissions for accessing files; see
169 .BR path_resolution (7)
170 for details.
171 Whenever a process's effective user (group) ID is changed,
172 the kernel also automatically changes the filesystem user (group) ID
173 to the same value.
174 Consequently, the filesystem IDs normally have the same values
175 as the corresponding effective ID, and the semantics for file-permission
176 checks are thus the same on Linux as on other UNIX systems.
177 The filesystem IDs can be made to differ from the effective IDs
178 by calling
179 .BR setfsuid (2)
180 and
181 .BR setfsgid (2).
182 .IP *
183 Supplementary group IDs.
184 This is a set of additional group IDs that are used for permission
185 checks when accessing files and other shared resources.
186 On Linux kernels before 2.6.4,
187 a process can be a member of up to 32 supplementary groups;
188 since kernel 2.6.4,
189 a process can be a member of up to 65536 supplementary groups.
190 The call
191 .I sysconf(_SC_NGROUPS_MAX)
192 can be used to determine the number of supplementary groups
193 of which a process may be a member.
194 .\" Since kernel 2.6.4, the limit is visible via the read-only file
195 .\" /proc/sys/kernel/ngroups_max.
196 .\" As at 2.6.22-rc2, this file is still read-only.
197 A process can obtain its set of supplementary group IDs using
198 .BR getgroups (2),
199 and can modify the set using
200 .BR setgroups (2).
201 .PP
202 A child process created by
203 .BR fork (2)
204 inherits copies of its parent's user and groups IDs.
205 During an
206 .BR execve (2),
207 a process's real user and group ID and supplementary
208 group IDs are preserved;
209 the effective and saved set IDs may be changed, as described in
210 .BR execve (2).
211
212 Aside from the purposes noted above,
213 a process's user IDs are also employed in a number of other contexts:
214 .IP * 3
215 when determining the permissions for sending signals\(emsee
216 .BR kill (2);
217 .IP *
218 when determining the permissions for setting
219 process-scheduling parameters (nice value, real time
220 scheduling policy and priority, CPU affinity, I/O priority) using
221 .BR setpriority (2),
222 .BR sched_setaffinity (2),
223 .BR sched_setscheduler (2),
224 .BR sched_setparam (2),
225 and
226 .BR ioprio_set (2);
227 .IP *
228 when checking resource limits; see
229 .BR getrlimit (2);
230 .IP *
231 when checking the limit on the number of inotify instances
232 that the process may create; see
233 .BR inotify (7).
234 .SH CONFORMING TO
235 Process IDs, parent process IDs, process group IDs, and session IDs
236 are specified in POSIX.1-2001.
237 The real, effective, and saved set user and groups IDs,
238 and the supplementary group IDs, are specified in POSIX.1-2001.
239 The filesystem user and group IDs are a Linux extension.
240 .SH NOTES
241 The POSIX threads specification requires that
242 credentials are shared by all of the threads in a process.
243 However, at the kernel level, Linux maintains separate user and group
244 credentials for each thread.
245 The NPTL threading implementation does some work to ensure
246 that any change to user or group credentials
247 (e.g., calls to
248 .BR setuid (2),
249 .BR setresuid (2))
250 is carried through to all of the POSIX threads in a process.
251 .SH SEE ALSO
252 .BR bash (1),
253 .BR csh (1),
254 .BR ps (1),
255 .BR access (2),
256 .BR execve (2),
257 .BR faccessat (2),
258 .BR fork (2),
259 .BR getpgrp (2),
260 .BR getpid (2),
261 .BR getppid (2),
262 .BR getsid (2),
263 .BR kill (2),
264 .BR killpg (2),
265 .BR setegid (2),
266 .BR seteuid (2),
267 .BR setfsgid (2),
268 .BR setfsuid (2),
269 .BR setgid (2),
270 .BR setgroups (2),
271 .BR setresgid (2),
272 .BR setresuid (2),
273 .BR setuid (2),
274 .BR waitpid (2),
275 .BR euidaccess (3),
276 .BR initgroups (3),
277 .BR tcgetpgrp (3),
278 .BR tcsetpgrp (3),
279 .BR capabilities (7),
280 .BR path_resolution (7),
281 .BR unix (7)