.\" Copyright (c) 1983 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\" @(#)1.1.t 6.2 (Berkeley) 5/12/86
.sh "Processes and protection
Host and process identifiers
Each UNIX host has associated with it a 32-bit host id, and a host
name of up to 64 characters (as defined by MAXHOSTNAMELEN in
These are set (by a privileged user)
and returned by the calls:
len = gethostname(buf, buflen)
result int len; result char *buf; int buflen;
On each host runs a set of \fIprocesses\fP.
Each process is largely independent of other processes,
having its own protection domain, address space, timers, and
an independent set of references to system or user implemented objects.
Each process in a host is named by an integer
called the \fIprocess id\fP. This number is
the \fIgetpid\fP routine:
On each UNIX host this identifier is guaranteed to be unique;
in a multi-host environment, the (hostid, process id) pairs are
Process creation and termination
A new process is created by making a logical duplicate of an
The \fIfork\fP call returns twice, once in the parent process, where
\fIpid\fP is the process identifier of the child,
and once in the child process where \fIpid\fP is 0.
The parent-child relationship induces a hierarchical structure on
the set of processes in the system.
A process may terminate by executing an \fIexit\fP call:
returning 8 bits of exit status to its parent.
When a child process exits or
terminates abnormally, the parent process receives
event which caused termination of the child process. A
second call provides a non-blocking interface and may also be used
to retrieve information about resources consumed by the process during its
result int pid; result union wait *astatus;
pid = wait3(astatus, options, arusage);
result int pid; result union waitstatus *astatus;
int options; result struct rusage *arusage;
A process can overlay itself with the memory image of another process,
passing the newly created process a set of parameters, using the call:
char *name, **argv, **envp;
The specified \fIname\fP must be a file which is in a format recognized
by the system, either a binary executable file or a file which causes
the execution of a specified interpreter program to process its contents.
Each process in the system has associated with it two user-id's:
a \fIreal user id\fP and a \fIeffective user id\fP, both 16 bit
unsigned integers (type \fBuid_t\fP).
Each process has an \fIreal accounting group id\fP and an \fIeffective
accounting group id\fP and a set of
\fIaccess group id's\fP. The group id's are 16 bit unsigned integers
Each process may be in several different access groups, with the maximum
concurrent number of access groups a system compilation parameter,
the constant NGROUPS in the file \fI<sys/param.h>\fP,
guaranteed to be at least 8.
The real and effective user ids associated with a process are returned by:
the real and effective accounting group ids by:
The access group id set is returned by a \fIgetgroups\fP call*:
ngroups = getgroups(gidsetsize, gidset);
result int ngroups; int gidsetsize; result int gidset[gidsetsize];
* The type of the gidset array in getgroups and setgroups
remains integer for compatibility with 4.2BSD.
It may change to \fBgid_t\fP in future releases.
are assigned at login time using the \fIsetreuid\fP, \fIsetregid\fP,
and \fIsetgroups\fP calls:
setgroups(gidsetsize, gidset)
int gidsetsize; int gidset[gidsetsize];
The \fIsetreuid\fP call sets both the real and effective user-id's,
while the \fIsetregid\fP call sets both the real
and effective accounting group id's.
Unless the caller is the super-user, \fIruid\fP
must be equal to either the current real or effective user-id,
and \fIrgid\fP equal to either the current real or effective
accounting group id. The \fIsetgroups\fP call is restricted
Each process in the system is also normally associated with a \fIprocess
group\fP. The group of processes in a process group is sometimes
referred to as a \fIjob\fP and manipulated by high-level system
software (such as the shell).
The current process group of a process is returned by the
result int pgrp; int pid;
When a process is in a specific process group it may receive
software interrupts affecting the group, causing the group to
suspend or resume execution or to be interrupted or terminated.
In particular, a system terminal has a process group and only processes
which are in the process group of the terminal may read from the
terminal, allowing arbitration of terminals among several different jobs.
The process group associated with a process may be changed by
Newly created processes are assigned process id's distinct from all
processes and process groups, and the same process group as their
parent. A normal (unprivileged) process may set its process group equal
to its process id. A privileged process may set the process group of any