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