1 .\" Copyright (c) 1983, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" @(#)1.1.t 8.1 (Berkeley) 6/8/93
35 .sh "Processes and protection
37 Host and process identifiers
39 Each UNIX host has associated with it a 32-bit host id, and a host
40 name of up to 256 characters (as defined by MAXHOSTNAMELEN in
42 These are set (by a privileged user)
43 and returned by the calls:
51 sethostname(name, len)
54 len = gethostname(buf, buflen)
55 result int len; result char *buf; int buflen;
57 On each host runs a set of \fIprocesses\fP.
58 Each process is largely independent of other processes,
59 having its own protection domain, address space, timers, and
60 an independent set of references to system or user implemented objects.
62 Each process in a host is named by an integer
63 called the \fIprocess id\fP. This number is
66 the \fIgetpid\fP routine:
71 On each UNIX host this identifier is guaranteed to be unique;
72 in a multi-host environment, the (hostid, process id) pairs are
75 Process creation and termination
77 A new process is created by making a logical duplicate of an
83 The \fIfork\fP call returns twice, once in the parent process, where
84 \fIpid\fP is the process identifier of the child,
85 and once in the child process where \fIpid\fP is 0.
86 The parent-child relationship induces a hierarchical structure on
87 the set of processes in the system.
89 A process may terminate by executing an \fIexit\fP call:
94 returning 8 bits of exit status to its parent.
96 When a child process exits or
97 terminates abnormally, the parent process receives
99 event which caused termination of the child process. A
100 second call provides a non-blocking interface and may also be used
101 to retrieve information about resources consumed by the process during its
104 #include <sys/wait.h>
107 result int pid; result union wait *astatus;
109 pid = wait3(astatus, options, arusage);
110 result int pid; result union waitstatus *astatus;
111 int options; result struct rusage *arusage;
114 A process can overlay itself with the memory image of another process,
115 passing the newly created process a set of parameters, using the call:
117 execve(name, argv, envp)
118 char *name, **argv, **envp;
120 The specified \fIname\fP must be a file which is in a format recognized
121 by the system, either a binary executable file or a file which causes
122 the execution of a specified interpreter program to process its contents.
126 Each process in the system has associated with it two user-id's:
127 a \fIreal user id\fP and a \fIeffective user id\fP, both 16 bit
128 unsigned integers (type \fBuid_t\fP).
129 Each process has an \fIreal accounting group id\fP and an \fIeffective
130 accounting group id\fP and a set of
131 \fIaccess group id's\fP. The group id's are 16 bit unsigned integers
133 Each process may be in several different access groups, with the maximum
134 concurrent number of access groups a system compilation parameter,
135 the constant NGROUPS in the file \fI<sys/param.h>\fP,
136 guaranteed to be at least 8.
138 The real and effective user ids associated with a process are returned by:
146 the real and effective accounting group ids by:
154 The access group id set is returned by a \fIgetgroups\fP call*:
156 ngroups = getgroups(gidsetsize, gidset);
157 result int ngroups; int gidsetsize; result int gidset[gidsetsize];
160 * The type of the gidset array in getgroups and setgroups
161 remains integer for compatibility with 4.2BSD.
162 It may change to \fBgid_t\fP in future releases.
165 The user and group id's
166 are assigned at login time using the \fIsetreuid\fP, \fIsetregid\fP,
167 and \fIsetgroups\fP calls:
169 setreuid(ruid, euid);
172 setregid(rgid, egid);
175 setgroups(gidsetsize, gidset)
176 int gidsetsize; int gidset[gidsetsize];
178 The \fIsetreuid\fP call sets both the real and effective user-id's,
179 while the \fIsetregid\fP call sets both the real
180 and effective accounting group id's.
181 Unless the caller is the super-user, \fIruid\fP
182 must be equal to either the current real or effective user-id,
183 and \fIrgid\fP equal to either the current real or effective
184 accounting group id. The \fIsetgroups\fP call is restricted
189 Each process in the system is also normally associated with a \fIprocess
190 group\fP. The group of processes in a process group is sometimes
191 referred to as a \fIjob\fP and manipulated by high-level system
192 software (such as the shell).
193 The current process group of a process is returned by the
197 result int pgrp; int pid;
199 When a process is in a specific process group it may receive
200 software interrupts affecting the group, causing the group to
201 suspend or resume execution or to be interrupted or terminated.
202 In particular, a system terminal has a process group and only processes
203 which are in the process group of the terminal may read from the
204 terminal, allowing arbitration of terminals among several different jobs.
206 The process group associated with a process may be changed by
207 the \fIsetpgrp\fP call:
212 Newly created processes are assigned process id's distinct from all
213 processes and process groups, and the same process group as their
214 parent. A normal (unprivileged) process may set its process group equal
215 to its process id. A privileged process may set the process group of any
216 process to any value.