]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/doc/psd/05.sysman/1.1.t
zfs: merge openzfs/zfs@688514e47
[FreeBSD/FreeBSD.git] / share / doc / psd / 05.sysman / 1.1.t
1 .\" Copyright (c) 1983, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .sh "Processes and protection
29 .NH 3
30 Host and process identifiers
31 .PP
32 Each UNIX host has associated with it a 32-bit host id, and a host
33 name of up to 256 characters (as defined by MAXHOSTNAMELEN in
34 \fI<sys/param.h>\fP).
35 These are set (by a privileged user)
36 and returned by the calls:
37 .DS
38 sethostid(hostid)
39 long hostid;
40
41 hostid = gethostid();
42 result long hostid;
43
44 sethostname(name, len)
45 char *name; int len;
46
47 len = gethostname(buf, buflen)
48 result int len; result char *buf; int buflen;
49 .DE
50 On each host runs a set of \fIprocesses\fP.
51 Each process is largely independent of other processes,
52 having its own protection domain, address space, timers, and
53 an independent set of references to system or user implemented objects.
54 .PP
55 Each process in a host is named by an integer
56 called the \fIprocess id\fP.  This number is
57 in the range 1-30000
58 and is returned by
59 the \fIgetpid\fP routine:
60 .DS
61 pid = getpid();
62 result int pid;
63 .DE
64 On each UNIX host this identifier is guaranteed to be unique;
65 in a multi-host environment, the (hostid, process id) pairs are
66 guaranteed unique.
67 .NH 3
68 Process creation and termination
69 .PP
70 A new process is created by making a logical duplicate of an
71 existing process:
72 .DS
73 pid = fork();
74 result int pid;
75 .DE
76 The \fIfork\fP call returns twice, once in the parent process, where
77 \fIpid\fP is the process identifier of the child,
78 and once in the child process where \fIpid\fP is 0.
79 The parent-child relationship induces a hierarchical structure on
80 the set of processes in the system.
81 .PP
82 A process may terminate by executing an \fIexit\fP call:
83 .DS
84 exit(status)
85 int status;
86 .DE
87 returning 8 bits of exit status to its parent.
88 .PP
89 When a child process exits or
90 terminates abnormally, the parent process receives
91 information about any
92 event which caused termination of the child process.  A
93 second call provides a non-blocking interface and may also be used
94 to retrieve information about resources consumed by the process during its
95 lifetime.
96 .DS
97 #include <sys/wait.h>
98
99 pid = wait(astatus);
100 result int pid; result union wait *astatus;
101
102 pid = wait3(astatus, options, arusage);
103 result int pid; result union waitstatus *astatus;
104 int options; result struct rusage *arusage;
105 .DE
106 .PP
107 A process can overlay itself with the memory image of another process,
108 passing the newly created process a set of parameters, using the call:
109 .DS
110 execve(name, argv, envp)
111 char *name, **argv, **envp;
112 .DE
113 The specified \fIname\fP must be a file which is in a format recognized
114 by the system, either a binary executable file or a file which causes
115 the execution of a specified interpreter program to process its contents.
116 .NH 3
117 User and group ids
118 .PP
119 Each process in the system has associated with it two user-id's:
120 a \fIreal user id\fP and a \fIeffective user id\fP, both 16 bit
121 unsigned integers (type \fBuid_t\fP).
122 Each process has an \fIreal accounting group id\fP and an \fIeffective
123 accounting group id\fP and a set of
124 \fIaccess group id's\fP.  The group id's are 16 bit unsigned integers
125 (type \fBgid_t\fP).
126 Each process may be in several different access groups, with the maximum
127 concurrent number of access groups a system compilation parameter,
128 the constant NGROUPS in the file \fI<sys/param.h>\fP,
129 guaranteed to be at least 8.
130 .PP
131 The real and effective user ids associated with a process are returned by:
132 .DS
133 ruid = getuid();
134 result uid_t ruid;
135
136 euid = geteuid();
137 result uid_t euid;
138 .DE
139 the real and effective accounting group ids by:
140 .DS
141 rgid = getgid();
142 result gid_t rgid;
143
144 egid = getegid();
145 result gid_t egid;
146 .DE
147 The access group id set is returned by a \fIgetgroups\fP call*:
148 .DS
149 ngroups = getgroups(gidsetsize, gidset);
150 result int ngroups; int gidsetsize; result int gidset[gidsetsize];
151 .DE
152 .FS
153 * The type of the gidset array in getgroups and setgroups
154 remains integer for compatibility with 4.2BSD.
155 It may change to \fBgid_t\fP in future releases.
156 .FE
157 .PP
158 The user and group id's
159 are assigned at login time using the \fIsetreuid\fP, \fIsetregid\fP,
160 and \fIsetgroups\fP calls:
161 .DS
162 setreuid(ruid, euid);
163 int ruid, euid;
164
165 setregid(rgid, egid);
166 int rgid, egid;
167
168 setgroups(gidsetsize, gidset)
169 int gidsetsize; int gidset[gidsetsize];
170 .DE
171 The \fIsetreuid\fP call sets both the real and effective user-id's,
172 while the \fIsetregid\fP call sets both the real
173 and effective accounting group id's.
174 Unless the caller is the super-user, \fIruid\fP
175 must be equal to either the current real or effective user-id,
176 and \fIrgid\fP equal to either the current real or effective
177 accounting group id.  The \fIsetgroups\fP call is restricted
178 to the super-user.
179 .NH 3
180 Process groups
181 .PP
182 Each process in the system is also normally associated with a \fIprocess
183 group\fP.  The group of processes in a process group is sometimes
184 referred to as a \fIjob\fP and manipulated by high-level system
185 software (such as the shell).
186 The current process group of a process is returned by the
187 \fIgetpgrp\fP call:
188 .DS
189 pgrp = getpgrp(pid);
190 result int pgrp; int pid;
191 .DE
192 When a process is in a specific process group it may receive
193 software interrupts affecting the group, causing the group to
194 suspend or resume execution or to be interrupted or terminated.
195 In particular, a system terminal has a process group and only processes
196 which are in the process group of the terminal may read from the
197 terminal, allowing arbitration of terminals among several different jobs.
198 .PP
199 The process group associated with a process may be changed by
200 the \fIsetpgrp\fP call:
201 .DS
202 setpgrp(pid, pgrp);
203 int pid, pgrp;
204 .DE
205 Newly created processes are assigned process id's distinct from all
206 processes and process groups, and the same process group as their
207 parent.  A normal (unprivileged) process may set its process group equal
208 to its process id.  A privileged process may set the process group of any
209 process to any value.