]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/doc/psd/05.sysman/1.1.t
Add 'contrib/unifdef/' from commit '0da44885831dc0a43c4ca6ff04a2430993cc0a80'
[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 .\"     @(#)1.1.t       8.1 (Berkeley) 6/8/93
29 .\"
30 .sh "Processes and protection
31 .NH 3
32 Host and process identifiers
33 .PP
34 Each UNIX host has associated with it a 32-bit host id, and a host
35 name of up to 256 characters (as defined by MAXHOSTNAMELEN in
36 \fI<sys/param.h>\fP).
37 These are set (by a privileged user)
38 and returned by the calls:
39 .DS
40 sethostid(hostid)
41 long hostid;
42
43 hostid = gethostid();
44 result long hostid;
45
46 sethostname(name, len)
47 char *name; int len;
48
49 len = gethostname(buf, buflen)
50 result int len; result char *buf; int buflen;
51 .DE
52 On each host runs a set of \fIprocesses\fP.
53 Each process is largely independent of other processes,
54 having its own protection domain, address space, timers, and
55 an independent set of references to system or user implemented objects.
56 .PP
57 Each process in a host is named by an integer
58 called the \fIprocess id\fP.  This number is
59 in the range 1-30000
60 and is returned by
61 the \fIgetpid\fP routine:
62 .DS
63 pid = getpid();
64 result int pid;
65 .DE
66 On each UNIX host this identifier is guaranteed to be unique;
67 in a multi-host environment, the (hostid, process id) pairs are
68 guaranteed unique.
69 .NH 3
70 Process creation and termination
71 .PP
72 A new process is created by making a logical duplicate of an
73 existing process:
74 .DS
75 pid = fork();
76 result int pid;
77 .DE
78 The \fIfork\fP call returns twice, once in the parent process, where
79 \fIpid\fP is the process identifier of the child,
80 and once in the child process where \fIpid\fP is 0.
81 The parent-child relationship induces a hierarchical structure on
82 the set of processes in the system.
83 .PP
84 A process may terminate by executing an \fIexit\fP call:
85 .DS
86 exit(status)
87 int status;
88 .DE
89 returning 8 bits of exit status to its parent.
90 .PP
91 When a child process exits or
92 terminates abnormally, the parent process receives
93 information about any
94 event which caused termination of the child process.  A
95 second call provides a non-blocking interface and may also be used
96 to retrieve information about resources consumed by the process during its
97 lifetime.
98 .DS
99 #include <sys/wait.h>
100
101 pid = wait(astatus);
102 result int pid; result union wait *astatus;
103
104 pid = wait3(astatus, options, arusage);
105 result int pid; result union waitstatus *astatus;
106 int options; result struct rusage *arusage;
107 .DE
108 .PP
109 A process can overlay itself with the memory image of another process,
110 passing the newly created process a set of parameters, using the call:
111 .DS
112 execve(name, argv, envp)
113 char *name, **argv, **envp;
114 .DE
115 The specified \fIname\fP must be a file which is in a format recognized
116 by the system, either a binary executable file or a file which causes
117 the execution of a specified interpreter program to process its contents.
118 .NH 3
119 User and group ids
120 .PP
121 Each process in the system has associated with it two user-id's:
122 a \fIreal user id\fP and a \fIeffective user id\fP, both 16 bit
123 unsigned integers (type \fBuid_t\fP).
124 Each process has an \fIreal accounting group id\fP and an \fIeffective
125 accounting group id\fP and a set of
126 \fIaccess group id's\fP.  The group id's are 16 bit unsigned integers
127 (type \fBgid_t\fP).
128 Each process may be in several different access groups, with the maximum
129 concurrent number of access groups a system compilation parameter,
130 the constant NGROUPS in the file \fI<sys/param.h>\fP,
131 guaranteed to be at least 8.
132 .PP
133 The real and effective user ids associated with a process are returned by:
134 .DS
135 ruid = getuid();
136 result uid_t ruid;
137
138 euid = geteuid();
139 result uid_t euid;
140 .DE
141 the real and effective accounting group ids by:
142 .DS
143 rgid = getgid();
144 result gid_t rgid;
145
146 egid = getegid();
147 result gid_t egid;
148 .DE
149 The access group id set is returned by a \fIgetgroups\fP call*:
150 .DS
151 ngroups = getgroups(gidsetsize, gidset);
152 result int ngroups; int gidsetsize; result int gidset[gidsetsize];
153 .DE
154 .FS
155 * The type of the gidset array in getgroups and setgroups
156 remains integer for compatibility with 4.2BSD.
157 It may change to \fBgid_t\fP in future releases.
158 .FE
159 .PP
160 The user and group id's
161 are assigned at login time using the \fIsetreuid\fP, \fIsetregid\fP,
162 and \fIsetgroups\fP calls:
163 .DS
164 setreuid(ruid, euid);
165 int ruid, euid;
166
167 setregid(rgid, egid);
168 int rgid, egid;
169
170 setgroups(gidsetsize, gidset)
171 int gidsetsize; int gidset[gidsetsize];
172 .DE
173 The \fIsetreuid\fP call sets both the real and effective user-id's,
174 while the \fIsetregid\fP call sets both the real
175 and effective accounting group id's.
176 Unless the caller is the super-user, \fIruid\fP
177 must be equal to either the current real or effective user-id,
178 and \fIrgid\fP equal to either the current real or effective
179 accounting group id.  The \fIsetgroups\fP call is restricted
180 to the super-user.
181 .NH 3
182 Process groups
183 .PP
184 Each process in the system is also normally associated with a \fIprocess
185 group\fP.  The group of processes in a process group is sometimes
186 referred to as a \fIjob\fP and manipulated by high-level system
187 software (such as the shell).
188 The current process group of a process is returned by the
189 \fIgetpgrp\fP call:
190 .DS
191 pgrp = getpgrp(pid);
192 result int pgrp; int pid;
193 .DE
194 When a process is in a specific process group it may receive
195 software interrupts affecting the group, causing the group to
196 suspend or resume execution or to be interrupted or terminated.
197 In particular, a system terminal has a process group and only processes
198 which are in the process group of the terminal may read from the
199 terminal, allowing arbitration of terminals among several different jobs.
200 .PP
201 The process group associated with a process may be changed by
202 the \fIsetpgrp\fP call:
203 .DS
204 setpgrp(pid, pgrp);
205 int pid, pgrp;
206 .DE
207 Newly created processes are assigned process id's distinct from all
208 processes and process groups, and the same process group as their
209 parent.  A normal (unprivileged) process may set its process group equal
210 to its process id.  A privileged process may set the process group of any
211 process to any value.