1 .\" $NetBSD: 1.1.t,v 1.2 1998/01/09 06:54:40 perry Exp $
3 .\" Copyright (c) 1983, 1993, 1994
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)1.1.t 8.5 (Berkeley) 5/26/94
32 .Sh 2 "Processes and protection
33 .Sh 3 "Host identifiers
35 Each host has associated with it an integer host ID, and a host
36 name of up to MAXHOSTNAMELEN (256) characters (as defined in
38 These identifiers are set (by a privileged user) and retrieved using the
40 interface described in section
42 The host ID is seldom used (or set), and is deprecated.
43 For convenience and backward compatibility,
44 the following library routines are provided:
46 .Fd sethostid 1 "set host identifier
51 .Fd gethostid 0 "get host identifier
56 .Fd sethostname 2 "set host name
57 sethostname(name, len);
61 .Fd gethostname 2 "get host name
62 len = gethostname(buf, buflen);
63 result int len; result char *buf; int buflen;
65 .Sh 3 "Process identifiers
66 Each host runs a set of \fIprocesses\fP.
67 Each process is largely independent of other processes,
68 having its own protection domain, address space, timers, and
69 an independent set of references to system or user implemented objects.
71 Each process in a host is named by an integer
72 called the \fIprocess ID\fP. This number is
74 and is returned by the
78 .Fd getpid 0 "get process identifier
82 On each host this identifier is guaranteed to be unique;
83 in a multi-host environment, the (hostid, process ID) pairs are
85 The parent process identifier can be obtained using the
89 .Fd getppid 0 "get parent process identifier
93 .Sh 3 "Process creation and termination
95 A new process is created by making a logical duplicate of an
98 .Fd fork 0 "create a new process
104 call returns twice, once in the parent process, where
105 \fIpid\fP is the process identifier of the child,
106 and once in the child process where \fIpid\fP is 0.
107 The parent-child relationship imposes a hierarchical structure on
108 the set of processes in the system.
110 For processes that are forking solely for the purpose of
114 system call provides a faster interface:
116 .Fd vfork 0 "create a new process
124 call returns twice, once in the parent process, where
125 \fIpid\fP is the process identifier of the child,
126 and once in the child process where \fIpid\fP is 0.
127 The parent process is suspended until the child process calls
128 either \fIexecve\fP or \fIexit\fP.
130 A process may terminate by executing an
134 .Fd exit 1 "terminate a process
138 The lower 8 bits of exit status are available to its parent.
140 When a child process exits or
141 terminates abnormally, the parent process receives
142 information about the
143 event which caused termination of the child process.
144 The interface allows the parent to wait for a particular process,
145 process group, or any direct descendent and
146 to retrieve information about resources consumed
147 by the process during its lifetime.
148 The request may be done either synchronously
149 (waiting for one of the requested processes to exit),
151 (polling to see if any of the requested processes have exited):
153 .Fd wait4 4 "collect exit status of child
154 pid = wait4(wpid, astatus, options, arusage);
155 result pid_t pid; pid_t wpid; result int *astatus;
156 int options; result struct rusage *arusage;
159 A process can overlay itself with the memory image of another process,
160 passing the newly created process a set of parameters, using the call:
162 .Fd execve 3 "execute a new program
163 execve(name, argv, envp);
164 char *name, *argv[], *envp[];
166 The specified \fIname\fP must be a file which is in a format recognized
167 by the system, either a binary executable file or a file which causes
168 the execution of a specified interpreter program to process its contents.
169 If the set-user-ID mode bit is set,
170 the effective user ID is set to the owner of the file;
171 if the set-group-ID mode bit is set,
172 the effective group ID is set to the group of the file.
173 Whether changed or not, the effective user ID is then copied to the
174 saved user ID, and the effective group ID is copied to the
176 .Sh 3 "User and group IDs
178 Each process in the system has associated with it three user IDs:
179 a \fIreal user ID\fP, an \fIeffective user ID\fP, and a \fIsaved user ID\fP,
180 all unsigned integral types (\fBuid_t\fP).
181 Each process has a \fIreal group ID\fP
182 and a set of \fIaccess group IDs\fP,
183 the first of which is the \fIeffective group ID\fP.
184 The group IDs are unsigned integral types (\fBgid_t\fP).
185 Each process may be in multiple access groups.
186 The maximum concurrent number of access groups is a system compilation
188 represented by the constant NGROUPS in the file \fI<sys/param.h>\fP.
189 It is guaranteed to be at least 16.
191 The real group ID is used in process accounting and in testing whether
192 the effective group ID may be changed; it is not otherwise used for
194 The members of the access group ID set are used for access control.
195 Because the first member of the set is the effective group ID, which
196 is changed when executing a set-group-ID program, that element is normally
197 duplicated in the set so that access privileges for the original group
198 are not lost when using a set-group-ID program.
200 The real and effective user IDs associated with a process are returned by:
202 .Fd getuid 0 "get real user identifier
207 .Fd geteuid 0 "get effective user identifier
211 the real and effective group IDs by:
213 .Fd getgid 0 "get real group identifier
218 .Fd getegid 0 "get effective group identifier
222 The access group ID set is returned by a
226 .Fd getgroups 2 "get access group set
227 ngroups = getgroups(gidsetsize, gidset);
228 result int ngroups; int gidsetsize; result gid_t gidset[gidsetsize];
231 The user and group IDs
232 are assigned at login time using the
239 .Fd setuid 1 "set real, effective, and saved user identifiers
244 .Fd setgid 1 "set real, effective, and saved group identifiers
249 .Fd setgroups 2 "set access group set
250 setgroups(gidsetsize, gidset);
251 int gidsetsize; gid_t gidset[gidsetsize];
255 call sets the real, effective, and saved user IDs,
256 and is permitted only if the specified \fIuid\fP is the current real user ID
257 or if the caller is the super-user.
260 call sets the real, effective, and saved group IDs;
261 it is permitted only if the specified \fIgid\fP is the current real group ID
262 or if the caller is the super-user.
265 call sets the access group ID set, and is restricted to the super-user.
269 routine allows any process to set its effective user ID to either its
270 real or saved user ID:
272 .Fd seteuid 1 "set effective user identifier
278 routine allows any process to set its effective group ID to either its
279 real or saved group ID:
281 .Fd setegid 1 "set effective group identifier
287 When a user first logs onto the system,
288 they are put into a session with a controlling process
290 The session is created with the call:
292 .Fd setsid 0 "create a new session
296 All subsequent processes created by the user
299 will be part of the session.
300 The session also has a login name associated with it
301 which is set using the privileged call:
303 .Fd setlogin 1 "set login name
307 The login name can be retrieved using the call:
309 .Fd getlogin 0 "get login name
313 Unlike historic systems, the value returned by
315 is stored in the kernel and can be trusted.
316 .Sh 3 "Process groups
318 Each process in the system is also associated with a \fIprocess
319 group\fP. The group of processes in a process group is sometimes
320 referred to as a \fIjob\fP and manipulated by high-level system
321 software (such as the shell).
322 All members of a process group are members of the same session.
323 The current process group of a process is returned by the
327 .Fd getpgrp 0 "get process group
331 When a process is in a specific process group it may receive
332 software interrupts affecting the group, causing the group to
333 suspend or resume execution or to be interrupted or terminated.
334 In particular, a system terminal has a process group and only processes
335 which are in the process group of the terminal may read from the terminal,
336 allowing arbitration of a terminal among several different jobs.
338 The process group associated with a process may be changed by the
342 .Fd setpgid 2 "set process group
346 Newly created processes are assigned process IDs distinct from all
347 processes and process groups, and the same process group as their
349 Any process may set its process group equal to its process ID or
350 to the value of any process group within its session.