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