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. 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.
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
28 .sh "Processes and protection
30 Host and process identifiers
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
35 These are set (by a privileged user)
36 and returned by the calls:
44 sethostname(name, len)
47 len = gethostname(buf, buflen)
48 result int len; result char *buf; int buflen;
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.
55 Each process in a host is named by an integer
56 called the \fIprocess id\fP. This number is
59 the \fIgetpid\fP routine:
64 On each UNIX host this identifier is guaranteed to be unique;
65 in a multi-host environment, the (hostid, process id) pairs are
68 Process creation and termination
70 A new process is created by making a logical duplicate of an
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.
82 A process may terminate by executing an \fIexit\fP call:
87 returning 8 bits of exit status to its parent.
89 When a child process exits or
90 terminates abnormally, the parent process receives
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
100 result int pid; result union wait *astatus;
102 pid = wait3(astatus, options, arusage);
103 result int pid; result union waitstatus *astatus;
104 int options; result struct rusage *arusage;
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:
110 execve(name, argv, envp)
111 char *name, **argv, **envp;
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.
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
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.
131 The real and effective user ids associated with a process are returned by:
139 the real and effective accounting group ids by:
147 The access group id set is returned by a \fIgetgroups\fP call*:
149 ngroups = getgroups(gidsetsize, gidset);
150 result int ngroups; int gidsetsize; result int gidset[gidsetsize];
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.
158 The user and group id's
159 are assigned at login time using the \fIsetreuid\fP, \fIsetregid\fP,
160 and \fIsetgroups\fP calls:
162 setreuid(ruid, euid);
165 setregid(rgid, egid);
168 setgroups(gidsetsize, gidset)
169 int gidsetsize; int gidset[gidsetsize];
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
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
190 result int pgrp; int pid;
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.
199 The process group associated with a process may be changed by
200 the \fIsetpgrp\fP call:
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.