1 .\" This module is believed to contain source code proprietary to AT&T.
2 .\" Use and redistribution is subject to the Berkeley Software License
3 .\" Agreement and your Software Agreement with AT&T (Western Electric).
5 .\" @(#)p3 8.1 (Berkeley) 6/8/93
9 V. PROCESSES AND IMAGES
13 is a computer execution environment.
14 It includes a memory image,
15 general register values,
17 current directory and the like.
18 An image is the current state of a pseudo-computer.
22 is the execution of an image.
23 While the processor is executing on behalf of a process,
24 the image must reside in main memory;
25 during the execution of other processes it remains in main memory
26 unless the appearance of an active, higher-priority
28 forces it to be swapped out to the disk.
30 The user-memory part of an image is divided into three logical segments.
31 The program text segment begins at location 0 in the virtual address space.
32 During execution, this segment is write-protected
33 and a single copy of it is shared among
34 all processes executing the same program.
35 At the first hardware protection byte boundary above the program text segment in the
36 virtual address space begins a non-shared, writable data segment,
37 the size of which may be extended by a system call.
38 Starting at the highest
39 address in the virtual address space is a stack segment,
40 which automatically grows downward
41 as the stack pointer fluctuates.
47 is bootstrapping itself into operation, a new
48 process can come into existence only
53 processid = fork\|(\|\|)\|
57 is executed, the process
58 splits into two independently executing processes.
59 The two processes have independent
60 copies of the original memory image,
61 and share all open files.
62 The new processes differ only in that one is considered
67 actually identifies the child process
70 the returned value is always 0.
72 Because the values returned by
74 in the parent and child process are distinguishable,
75 each process may determine whether
76 it is the parent or child.
80 Processes may communicate
81 with related processes using the same system
85 calls that are used for file-system I/O.
88 filep = pipe\|(\|\|)\|
90 returns a file descriptor
93 creates an inter-process channel called a
95 This channel, like other open files, is passed from parent to child process in
101 using a pipe file descriptor
102 waits until another process writes using the
103 file descriptor for the same pipe.
104 At this point, data are passed between the images of the
106 Neither process need know that a pipe,
107 rather than an ordinary file,
111 inter-process communication
112 via pipes is a quite valuable tool
114 it is not a completely general
116 because the pipe must be set up by a common ancestor
117 of the processes involved.
119 5.3 Execution of programs
121 Another major system primitive
124 execute\|(\|file, arg\*s\d1\u\*n, arg\*s\d2\u\*n, .\|.\|. , arg\*s\dn\u\*n\|)\|
126 which requests the system to read in and execute the program
129 passing it string arguments
130 .UL arg\v'.3'\*s1\*n\v'-.3'\| ,
131 .UL arg\v'.3'\*s2\*n\v'-.3'\| ,
133 .UL arg\v'.3'\*sn\*n\v'-.3' .
134 All the code and data in the process invoking
139 open files, current directory, and
140 inter-process relationships are unaltered.
141 Only if the call fails, for example
144 could not be found or because
145 its execute-permission bit was not set, does a return
149 it resembles a ``jump'' machine instruction
150 rather than a subroutine call.
152 5.4 Process synchronization
154 Another process control system call:
156 processid = wait\|(\|status\|)\|
158 causes its caller to suspend
159 execution until one of its children has completed execution.
164 of the terminated process.
165 An error return is taken if the calling process has no
167 Certain status from the child process
176 terminates a process,
178 closes its open files,
179 and generally obliterates it.
180 The parent is notified through
188 Processes may also terminate as a result of
189 various illegal actions or user-generated signals