.\" @(#)p3 6.1 (Berkeley) %G%
is a computer execution environment.
It includes a memory image,
current directory and the like.
An image is the current state of a pseudo-computer.
is the execution of an image.
While the processor is executing on behalf of a process,
the image must reside in main memory;
during the execution of other processes it remains in main memory
unless the appearance of an active, higher-priority
forces it to be swapped out to the disk.
The user-memory part of an image is divided into three logical segments.
The program text segment begins at location 0 in the virtual address space.
During execution, this segment is write-protected
and a single copy of it is shared among
all processes executing the same program.
At the first hardware protection byte boundary above the program text segment in the
virtual address space begins a non-shared, writable data segment,
the size of which may be extended by a system call.
address in the virtual address space is a stack segment,
which automatically grows downward
as the stack pointer fluctuates.
is bootstrapping itself into operation, a new
process can come into existence only
processid = fork\|(\|\|)\|
splits into two independently executing processes.
The two processes have independent
copies of the original memory image,
and share all open files.
The new processes differ only in that one is considered
actually identifies the child process
the returned value is always 0.
Because the values returned by
in the parent and child process are distinguishable,
each process may determine whether
it is the parent or child.
Processes may communicate
with related processes using the same system
calls that are used for file-system I/O.
returns a file descriptor
creates an inter-process channel called a
This channel, like other open files, is passed from parent to child process in
using a pipe file descriptor
waits until another process writes using the
file descriptor for the same pipe.
At this point, data are passed between the images of the
Neither process need know that a pipe,
rather than an ordinary file,
inter-process communication
via pipes is a quite valuable tool
it is not a completely general
because the pipe must be set up by a common ancestor
of the processes involved.
5.3 Execution of programs
Another major system primitive
execute\|(\|file, arg\*s\d1\u\*n, arg\*s\d2\u\*n, .\|.\|. , arg\*s\dn\u\*n\|)\|
which requests the system to read in and execute the program
passing it string arguments
.UL arg\v'.3'\*s1\*n\v'-.3'\| ,
.UL arg\v'.3'\*s2\*n\v'-.3'\| ,
.UL arg\v'.3'\*sn\*n\v'-.3' .
All the code and data in the process invoking
open files, current directory, and
inter-process relationships are unaltered.
Only if the call fails, for example
could not be found or because
its execute-permission bit was not set, does a return
it resembles a ``jump'' machine instruction
rather than a subroutine call.
5.4 Process synchronization
Another process control system call:
processid = wait\|(\|status\|)\|
causes its caller to suspend
execution until one of its children has completed execution.
of the terminated process.
An error return is taken if the calling process has no
Certain status from the child process
and generally obliterates it.
The parent is notified through
Processes may also terminate as a result of
various illegal actions or user-generated signals