annotate docs/nitros9guide/chap5.chapter @ 2112:cfb3a637a000

Fixed lack of H6309 flag
author boisy
date Tue, 21 Aug 2007 17:05:14 +0000
parents b00cf13c9f61
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
099333bc912e More splitups.
roug
parents:
diff changeset
1 <chapter>
099333bc912e More splitups.
roug
parents:
diff changeset
2 <title>Multiprogramming and Memory Management</title>
099333bc912e More splitups.
roug
parents:
diff changeset
3 <para>
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
4 One of NitrOS-9's most extraordinary abilities is multiprogramming,
145
099333bc912e More splitups.
roug
parents:
diff changeset
5 which is sometimes called timesharing or multitasking. Simply
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
6 states, NitrOS-9 lets you computer run more than one program at the same
145
099333bc912e More splitups.
roug
parents:
diff changeset
7 time. This can be a tremendous advantage in many situations. For
099333bc912e More splitups.
roug
parents:
diff changeset
8 example, you can be editing one program while another is being
099333bc912e More splitups.
roug
parents:
diff changeset
9 printed. Or you can use your Color Computer to control household
099333bc912e More splitups.
roug
parents:
diff changeset
10 automation and still be able to use it for routine work and
099333bc912e More splitups.
roug
parents:
diff changeset
11 entertainment.
099333bc912e More splitups.
roug
parents:
diff changeset
12 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
13 <para>
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
14 NitrOS-9 uses this capability all the time for internal functions.
145
099333bc912e More splitups.
roug
parents:
diff changeset
15 The simple way for you to do so is by putting a &quot;&amp;&quot; character at the
099333bc912e More splitups.
roug
parents:
diff changeset
16 end of a command line which causes the shell to run your command as
099333bc912e More splitups.
roug
parents:
diff changeset
17 a &quot;background task&quot;.
099333bc912e More splitups.
roug
parents:
diff changeset
18 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
19 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
20 The information presented in this chapter is intended to give you
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
21 an insight into how NitrOS-9 performs this amazing feat. You certainly
145
099333bc912e More splitups.
roug
parents:
diff changeset
22 don't have to know every detail of how multiprogramming works in
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
23 order to use NitrOS-9, but a basic working knowledge can help you
145
099333bc912e More splitups.
roug
parents:
diff changeset
24 discover many new ways to use your Color Computer.
099333bc912e More splitups.
roug
parents:
diff changeset
25 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
26 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
27 In order to allow several programs to run simultaneously and
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
28 without interference, NitrOS-9 must perform many coordination and
145
099333bc912e More splitups.
roug
parents:
diff changeset
29 resource allocation functions. The major system resources managed
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
30 by NitrOS-9 are:
145
099333bc912e More splitups.
roug
parents:
diff changeset
31 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
32 <simplelist>
099333bc912e More splitups.
roug
parents:
diff changeset
33 <member>CPU Time</member>
099333bc912e More splitups.
roug
parents:
diff changeset
34 <member>Memory</member>
099333bc912e More splitups.
roug
parents:
diff changeset
35 <member>The input/output system</member>
099333bc912e More splitups.
roug
parents:
diff changeset
36 </simplelist>
099333bc912e More splitups.
roug
parents:
diff changeset
37 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
38 In order for the computer to have reasonable performance, these
099333bc912e More splitups.
roug
parents:
diff changeset
39 resources must be managed in the most efficient manner possible.
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
40 Therefore, NitrOS-9 uses many techniques and strategies to optimize
145
099333bc912e More splitups.
roug
parents:
diff changeset
41 system throughput and capacity.
099333bc912e More splitups.
roug
parents:
diff changeset
42 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
43
1093
4dae346c4969 Added crossreferences and lowercased synopsises
roug
parents: 1053
diff changeset
44 <section id="sec5.1">
145
099333bc912e More splitups.
roug
parents:
diff changeset
45 <title>Processor Time Allocation and Timeslicing</title>
099333bc912e More splitups.
roug
parents:
diff changeset
46
099333bc912e More splitups.
roug
parents:
diff changeset
47 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
48 CPU time is a resource that must be allocated wisely to maximize
099333bc912e More splitups.
roug
parents:
diff changeset
49 the computer's throughput. It is characteristic of many programs to
099333bc912e More splitups.
roug
parents:
diff changeset
50 spend much unproductive time waiting for various events, such as an
099333bc912e More splitups.
roug
parents:
diff changeset
51 input/output operation. A good example is an interactive program
099333bc912e More splitups.
roug
parents:
diff changeset
52 which communicates with a person at a terminal on a line-by line
099333bc912e More splitups.
roug
parents:
diff changeset
53 basis. Every time the program has to wait for a line of characters
099333bc912e More splitups.
roug
parents:
diff changeset
54 to be typed or displayed, it (typically) cannot do any useful
099333bc912e More splitups.
roug
parents:
diff changeset
55 processing and would waste CPU time. An efficient multiprogramming
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
56 operating system such as NitrOS-9 automatically assigns CPU time to only
145
099333bc912e More splitups.
roug
parents:
diff changeset
57 those programs that can effectively use the, time.
099333bc912e More splitups.
roug
parents:
diff changeset
58 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
59 <para>
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
60 NitrOS-9 uses a technique called <emphasis>timeslicing</emphasis> which allows processes
145
099333bc912e More splitups.
roug
parents:
diff changeset
61 to share CPU time with all other active processes. Timeslicing is
099333bc912e More splitups.
roug
parents:
diff changeset
62 implemented using both hardware and software functions. The
099333bc912e More splitups.
roug
parents:
diff changeset
63 system's CPU is interrupted by a real time clock many (60 in the
099333bc912e More splitups.
roug
parents:
diff changeset
64 Color Computer) times each second. This basic time interval is
099333bc912e More splitups.
roug
parents:
diff changeset
65 called a &quot;tick&quot;, hence, the interval between ticks is a time slice.
099333bc912e More splitups.
roug
parents:
diff changeset
66 This technique is called timeslicing because each second of CPU time
099333bc912e More splitups.
roug
parents:
diff changeset
67 is sliced up to be shared among several processes. This happens so
099333bc912e More splitups.
roug
parents:
diff changeset
68 rapidly that to a human observer all processes appear to execute
099333bc912e More splitups.
roug
parents:
diff changeset
69 continuously, unless the computer becomes overloaded with processing. If this
099333bc912e More splitups.
roug
parents:
diff changeset
70 happens, a noticeable delay in response to terminal
099333bc912e More splitups.
roug
parents:
diff changeset
71 input may occur, or &quot;batch&quot; programs may take much longer to run
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
72 than they ordinarily do. At any occurrence of a tick, NitrOS-9 can suspend
145
099333bc912e More splitups.
roug
parents:
diff changeset
73 execution of one program and begin execution of another. The
099333bc912e More splitups.
roug
parents:
diff changeset
74 starting and stopping of programs is done in a manner that does not
099333bc912e More splitups.
roug
parents:
diff changeset
75 affect the program's execution. How frequently a process is given
099333bc912e More splitups.
roug
parents:
diff changeset
76 time slices depends upon its assigned priority relative to the
099333bc912e More splitups.
roug
parents:
diff changeset
77 assigned priority of other active processes.
099333bc912e More splitups.
roug
parents:
diff changeset
78 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
79 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
80 The percentage of CPU time assigned to any particular process
099333bc912e More splitups.
roug
parents:
diff changeset
81 cannot be exactly computed because there are dynamic variables such
099333bc912e More splitups.
roug
parents:
diff changeset
82 as time the process spends waiting for I/O devices. It can be
099333bc912e More splitups.
roug
parents:
diff changeset
83 roughly approximated by dividing the process's priority by the sum
099333bc912e More splitups.
roug
parents:
diff changeset
84 of the priority numbers of all processes:
099333bc912e More splitups.
roug
parents:
diff changeset
85 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
86 <screen>
099333bc912e More splitups.
roug
parents:
diff changeset
87
099333bc912e More splitups.
roug
parents:
diff changeset
88 Process Priority
099333bc912e More splitups.
roug
parents:
diff changeset
89 Process CPU Share = -------------------
099333bc912e More splitups.
roug
parents:
diff changeset
90 Sum of All Active
099333bc912e More splitups.
roug
parents:
diff changeset
91 Process' Priorities
099333bc912e More splitups.
roug
parents:
diff changeset
92 </screen>
099333bc912e More splitups.
roug
parents:
diff changeset
93 </section>
099333bc912e More splitups.
roug
parents:
diff changeset
94
1093
4dae346c4969 Added crossreferences and lowercased synopsises
roug
parents: 1053
diff changeset
95 <section id="sec5.2">
145
099333bc912e More splitups.
roug
parents:
diff changeset
96 <title>Process States</title>
099333bc912e More splitups.
roug
parents:
diff changeset
97
099333bc912e More splitups.
roug
parents:
diff changeset
98 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
99 The CPU time allocation system automatically assigns programs one
099333bc912e More splitups.
roug
parents:
diff changeset
100 of three &quot;states&quot; that describe their current status. Process
099333bc912e More splitups.
roug
parents:
diff changeset
101 states are also important for coordinating process execution. A
099333bc912e More splitups.
roug
parents:
diff changeset
102 process may be in one and only one state at any instant, although
099333bc912e More splitups.
roug
parents:
diff changeset
103 state changes may be frequent. The states are:
099333bc912e More splitups.
roug
parents:
diff changeset
104
099333bc912e More splitups.
roug
parents:
diff changeset
105
099333bc912e More splitups.
roug
parents:
diff changeset
106 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
107 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
108 <emphasis>ACTIVE:</emphasis>
099333bc912e More splitups.
roug
parents:
diff changeset
109 processes which can currently perform useful processing.
099333bc912e More splitups.
roug
parents:
diff changeset
110 These are the only processes assigned CPU time.
099333bc912e More splitups.
roug
parents:
diff changeset
111 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
112 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
113 <emphasis>WAITING:</emphasis>
099333bc912e More splitups.
roug
parents:
diff changeset
114 processes which have been suspended until another process
099333bc912e More splitups.
roug
parents:
diff changeset
115 terminates. This state is used to coordinate execution of
099333bc912e More splitups.
roug
parents:
diff changeset
116 sequential programs. The shell, for example, will be in the waiting
099333bc912e More splitups.
roug
parents:
diff changeset
117 state during the time a command program it has initiated is running.
099333bc912e More splitups.
roug
parents:
diff changeset
118
099333bc912e More splitups.
roug
parents:
diff changeset
119 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
120 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
121 <emphasis>SLEEPING:</emphasis>
099333bc912e More splitups.
roug
parents:
diff changeset
122 processes suspended by self-request for a specified time
099333bc912e More splitups.
roug
parents:
diff changeset
123 interval or until receipt of a &quot;signal&quot;. Signals are internal
099333bc912e More splitups.
roug
parents:
diff changeset
124 messages used to coordinate concurrent processes. This is the
099333bc912e More splitups.
roug
parents:
diff changeset
125 typical state of programs which are waiting for input/output
099333bc912e More splitups.
roug
parents:
diff changeset
126 operations.
099333bc912e More splitups.
roug
parents:
diff changeset
127
099333bc912e More splitups.
roug
parents:
diff changeset
128 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
129 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
130
099333bc912e More splitups.
roug
parents:
diff changeset
131 Sleeping and waiting processes are not given CPU time until they
099333bc912e More splitups.
roug
parents:
diff changeset
132 change to the active state.
099333bc912e More splitups.
roug
parents:
diff changeset
133 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
134 </section>
099333bc912e More splitups.
roug
parents:
diff changeset
135
1093
4dae346c4969 Added crossreferences and lowercased synopsises
roug
parents: 1053
diff changeset
136 <section id="sec5.3">
145
099333bc912e More splitups.
roug
parents:
diff changeset
137 <title>Creation of New Processes</title>
099333bc912e More splitups.
roug
parents:
diff changeset
138
099333bc912e More splitups.
roug
parents:
diff changeset
139 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
140 The sequence of operations required to create a new process and
099333bc912e More splitups.
roug
parents:
diff changeset
141 initially allocate its resources (especially memory) are
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
142 automatically performed by NitrOS-9's &quot;fork&quot; function. If for any
145
099333bc912e More splitups.
roug
parents:
diff changeset
143 reason any part of the sequence cannot be performed the fork is
099333bc912e More splitups.
roug
parents:
diff changeset
144 aborted and the prospective parent is passed an appropriate error
099333bc912e More splitups.
roug
parents:
diff changeset
145 code. The most frequent reason for failure is unavailablity of
099333bc912e More splitups.
roug
parents:
diff changeset
146 required resources (especially memory) or when the program specified
099333bc912e More splitups.
roug
parents:
diff changeset
147 to be run cannot be found. A process can create many new processes,
099333bc912e More splitups.
roug
parents:
diff changeset
148 subject only to the limitation of the amount of unassigned memory
099333bc912e More splitups.
roug
parents:
diff changeset
149 available.
099333bc912e More splitups.
roug
parents:
diff changeset
150 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
151 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
152 When a process creates a new process, the creator is called the
099333bc912e More splitups.
roug
parents:
diff changeset
153 &quot;parent process&quot;, and the newly created process is called the &quot;child
099333bc912e More splitups.
roug
parents:
diff changeset
154 process&quot;. The new child can itself become a parent by creating yet
099333bc912e More splitups.
roug
parents:
diff changeset
155 another process. If a parent process creates more than one child
099333bc912e More splitups.
roug
parents:
diff changeset
156 process, the children are called &quot;siblings&quot; with respect to each
099333bc912e More splitups.
roug
parents:
diff changeset
157 other. If the parent/child relationship of all processes in the
099333bc912e More splitups.
roug
parents:
diff changeset
158 system is examined, a hierarchical lineage becomes evident. In
099333bc912e More splitups.
roug
parents:
diff changeset
159 fact, this hierarchy is a tree structure that resembles a family
099333bc912e More splitups.
roug
parents:
diff changeset
160 tree. The &quot;family&quot; concept makes it easy to describe relationships
099333bc912e More splitups.
roug
parents:
diff changeset
161 between processes, and so it is used extensively in descriptions of
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
162 NitrOS-9's multiprogramming operations.
145
099333bc912e More splitups.
roug
parents:
diff changeset
163 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
164 <para>
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
165 When the parent issues a fork request to NitrOS-9, it must specify
145
099333bc912e More splitups.
roug
parents:
diff changeset
166 the following required information:
099333bc912e More splitups.
roug
parents:
diff changeset
167 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
168 <itemizedlist mark="square">
099333bc912e More splitups.
roug
parents:
diff changeset
169 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
170 A PRIMARY MODULE, which is the name of the program to be
099333bc912e More splitups.
roug
parents:
diff changeset
171 executed by the new process. The program can already be present
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
172 in memory, or NitrOS-9 may load it from a mass storage file having
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
173 the same name.
145
099333bc912e More splitups.
roug
parents:
diff changeset
174 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
175 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
176 PARAMETERS, which is data specified by the parent to be
099333bc912e More splitups.
roug
parents:
diff changeset
177 passed to and used by the new process. This data is copied to
099333bc912e More splitups.
roug
parents:
diff changeset
178 part of the child process' memory area. Parameters are
099333bc912e More splitups.
roug
parents:
diff changeset
179 frequently used to pass file names, initialization values, etc.
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
180 The shell, passes command line parameters this way.
145
099333bc912e More splitups.
roug
parents:
diff changeset
181 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
182 </itemizedlist>
099333bc912e More splitups.
roug
parents:
diff changeset
183 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
184 The new process also &quot;inherits&quot; copies of certain of its parent's
099333bc912e More splitups.
roug
parents:
diff changeset
185 properties. These are:
099333bc912e More splitups.
roug
parents:
diff changeset
186 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
187 <itemizedlist mark="square">
099333bc912e More splitups.
roug
parents:
diff changeset
188 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
189 A USER NUMBER which is used by the file security system and
099333bc912e More splitups.
roug
parents:
diff changeset
190 is used to identify all processes belonging to a specific user
099333bc912e More splitups.
roug
parents:
diff changeset
191 (this is not the same as the &quot;process ID&quot;, which identifies a
099333bc912e More splitups.
roug
parents:
diff changeset
192 specific process) . This number is usually obtained from the
099333bc912e More splitups.
roug
parents:
diff changeset
193 system password file when a user logs on. The system manager
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
194 always is user number zero.
145
099333bc912e More splitups.
roug
parents:
diff changeset
195 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
196 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
197 STANDARD INPUT AND OUTPUT PATHS: the three paths (input,
099333bc912e More splitups.
roug
parents:
diff changeset
198 output, and error/status) used for routine input and output.
099333bc912e More splitups.
roug
parents:
diff changeset
199 Note that most paths (files) may be shared simultaneously by
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
200 two or more processes. The two current working
145
099333bc912e More splitups.
roug
parents:
diff changeset
201 directories are also inherited.
099333bc912e More splitups.
roug
parents:
diff changeset
202 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
203 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
204 PROCESS PRIORITY which determines what proportion of CPU
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
205 time the process receives with respect to others.
145
099333bc912e More splitups.
roug
parents:
diff changeset
206 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
207 </itemizedlist>
099333bc912e More splitups.
roug
parents:
diff changeset
208 <para>
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
209 As part of the fork operation, NitrOS-9 automatically assigns:
145
099333bc912e More splitups.
roug
parents:
diff changeset
210 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
211 <itemizedlist mark="square">
099333bc912e More splitups.
roug
parents:
diff changeset
212 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
213 A PROCESS ID: a number from 1 to 255, which is used to
099333bc912e More splitups.
roug
parents:
diff changeset
214 identify specific processes. Each process has a unique process
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
215 ID number.
145
099333bc912e More splitups.
roug
parents:
diff changeset
216 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
217 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
218 MEMORY: enough memory required for the new process to run.
099333bc912e More splitups.
roug
parents:
diff changeset
219 Level Two systems give each process a unique &quot;address space&quot;.
099333bc912e More splitups.
roug
parents:
diff changeset
220 In Level One systems, all processes share the single address
099333bc912e More splitups.
roug
parents:
diff changeset
221 space. A &quot;data area&quot;, used for the program's parameters,
099333bc912e More splitups.
roug
parents:
diff changeset
222 variables, and stack is allocated for the process' exclusive
099333bc912e More splitups.
roug
parents:
diff changeset
223 use. A second memory area may also be required to load the
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
224 program (primary module) if it is not resident in memory.
145
099333bc912e More splitups.
roug
parents:
diff changeset
225 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
226 </itemizedlist>
099333bc912e More splitups.
roug
parents:
diff changeset
227 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
228 To summarize, the following items are given to or associated with
099333bc912e More splitups.
roug
parents:
diff changeset
229 new processes:
099333bc912e More splitups.
roug
parents:
diff changeset
230 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
231
099333bc912e More splitups.
roug
parents:
diff changeset
232 <itemizedlist mark="square">
099333bc912e More splitups.
roug
parents:
diff changeset
233 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
234 Primary Module (program module to be run)
099333bc912e More splitups.
roug
parents:
diff changeset
235 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
236 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
237 Parameter(s) passed from parent to child
099333bc912e More splitups.
roug
parents:
diff changeset
238 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
239 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
240 User Number
099333bc912e More splitups.
roug
parents:
diff changeset
241 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
242 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
243 Standard I/O paths and working directories
099333bc912e More splitups.
roug
parents:
diff changeset
244 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
245 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
246 Process Priority
099333bc912e More splitups.
roug
parents:
diff changeset
247 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
248 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
249 Process ID
099333bc912e More splitups.
roug
parents:
diff changeset
250 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
251 <listitem><para>
099333bc912e More splitups.
roug
parents:
diff changeset
252 Memory
099333bc912e More splitups.
roug
parents:
diff changeset
253 </para></listitem>
099333bc912e More splitups.
roug
parents:
diff changeset
254 </itemizedlist>
099333bc912e More splitups.
roug
parents:
diff changeset
255
099333bc912e More splitups.
roug
parents:
diff changeset
256 </section>
099333bc912e More splitups.
roug
parents:
diff changeset
257
1093
4dae346c4969 Added crossreferences and lowercased synopsises
roug
parents: 1053
diff changeset
258 <section id="sec5.4">
145
099333bc912e More splitups.
roug
parents:
diff changeset
259 <title>Basic Memory Management Functions</title>
099333bc912e More splitups.
roug
parents:
diff changeset
260 <para>
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
261 An important NitrOS-9 function is memory management. NitrOS-9 automatically allocates
145
099333bc912e More splitups.
roug
parents:
diff changeset
262 all system memory to itself and to processes, and
099333bc912e More splitups.
roug
parents:
diff changeset
263 also keeps track of the logical <emphasis>contents</emphasis>
099333bc912e More splitups.
roug
parents:
diff changeset
264 of memory (meaning which
099333bc912e More splitups.
roug
parents:
diff changeset
265 program modules are resident in memory at any given time). The
099333bc912e More splitups.
roug
parents:
diff changeset
266 result is that you seldom have to be bothered with the actual memory
099333bc912e More splitups.
roug
parents:
diff changeset
267 addresses of programs or data.
099333bc912e More splitups.
roug
parents:
diff changeset
268 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
269 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
270 Within the address space, memory is assigned from higher
099333bc912e More splitups.
roug
parents:
diff changeset
271 addresses downward for program modules, and from lower addresses
099333bc912e More splitups.
roug
parents:
diff changeset
272 upward for data areas, as shown below:
099333bc912e More splitups.
roug
parents:
diff changeset
273 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
274 <screen>
099333bc912e More splitups.
roug
parents:
diff changeset
275 +---------------------------+ highest address
099333bc912e More splitups.
roug
parents:
diff changeset
276 ! program modules !
099333bc912e More splitups.
roug
parents:
diff changeset
277 ! (RAM or ROM) !
099333bc912e More splitups.
roug
parents:
diff changeset
278 ! !
099333bc912e More splitups.
roug
parents:
diff changeset
279 ! - - - - - - - - - - - - - !
099333bc912e More splitups.
roug
parents:
diff changeset
280 ! !
099333bc912e More splitups.
roug
parents:
diff changeset
281 ! unused space !
099333bc912e More splitups.
roug
parents:
diff changeset
282 ! (RAM or empty) !
099333bc912e More splitups.
roug
parents:
diff changeset
283 ! !
099333bc912e More splitups.
roug
parents:
diff changeset
284 ! - - - - - - - - - - - - - !
099333bc912e More splitups.
roug
parents:
diff changeset
285 ! !
099333bc912e More splitups.
roug
parents:
diff changeset
286 ! data areas !
099333bc912e More splitups.
roug
parents:
diff changeset
287 ! (RAM) !
099333bc912e More splitups.
roug
parents:
diff changeset
288 ! !
099333bc912e More splitups.
roug
parents:
diff changeset
289 +---------------------------+ lowest address (0)
099333bc912e More splitups.
roug
parents:
diff changeset
290 </screen>
1093
4dae346c4969 Added crossreferences and lowercased synopsises
roug
parents: 1053
diff changeset
291 <section id="sec5.4.1">
145
099333bc912e More splitups.
roug
parents:
diff changeset
292 <title>Loading Program Modules Into Memory</title>
099333bc912e More splitups.
roug
parents:
diff changeset
293
099333bc912e More splitups.
roug
parents:
diff changeset
294 <para>
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
295 When performing a fork operation, NitrOS-9's first step is to attempt
145
099333bc912e More splitups.
roug
parents:
diff changeset
296 to locate the requested program module by searching the &quot;module
099333bc912e More splitups.
roug
parents:
diff changeset
297 directory&quot;, which has the address of every module present in memory.
1014
d9ed9d44b70c Some character entities had missing semicolons. It's &CPU;
roug
parents: 1011
diff changeset
298 The &CPU; instruction set supports a type of program called
145
099333bc912e More splitups.
roug
parents:
diff changeset
299 &quot;reentrant code&quot; which means the exact same &quot;copy&quot; of a program can
099333bc912e More splitups.
roug
parents:
diff changeset
300 be shared by two or more different processes simultaneously without
099333bc912e More splitups.
roug
parents:
diff changeset
301 affecting each other, provided that each &quot;incarnation&quot; of the
099333bc912e More splitups.
roug
parents:
diff changeset
302 program has am independent memory area for its variables.
099333bc912e More splitups.
roug
parents:
diff changeset
303 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
304 <para>
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
305 Almost all NitrOS-9 family software is reentrant and can make most
145
099333bc912e More splitups.
roug
parents:
diff changeset
306 efficient use of memory. For example, Basic09 requires 22K bytes of
099333bc912e More splitups.
roug
parents:
diff changeset
307 memory to load into. If a request to run Basic09 is made, but
099333bc912e More splitups.
roug
parents:
diff changeset
308 another user (process) had previously caused it to be loaded into
099333bc912e More splitups.
roug
parents:
diff changeset
309 memory, both processes will share the same copy, instead of causing
099333bc912e More splitups.
roug
parents:
diff changeset
310 another copy to be loaded (which would use an additional 22K of
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
311 memory). NitrOS-9 automatically keeps track of how many processes are
145
099333bc912e More splitups.
roug
parents:
diff changeset
312 using each program module and deletes the module (freeing its memory
099333bc912e More splitups.
roug
parents:
diff changeset
313 for other uses) when all processes using the module have terminated.
099333bc912e More splitups.
roug
parents:
diff changeset
314 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
315 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
316 If the requested program module is not already in memory, the
099333bc912e More splitups.
roug
parents:
diff changeset
317 name is used as a pathlist (file name) and an attempt is made to
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
318 load the program from mass storage.
145
099333bc912e More splitups.
roug
parents:
diff changeset
319 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
320 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
321 Every program module has a &quot;module header&quot; that describes the
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
322 program and its memory requirements. NitrOS-9 uses this to determine
145
099333bc912e More splitups.
roug
parents:
diff changeset
323 how much memory for variable storage should be allocated to the
099333bc912e More splitups.
roug
parents:
diff changeset
324 process (it can be given more memory by specifying an optional
099333bc912e More splitups.
roug
parents:
diff changeset
325 parameter on the shell command line). The module header also
099333bc912e More splitups.
roug
parents:
diff changeset
326 includes other important descriptive information about the program,
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
327 and is an essential part of NitrOS-9 operation at the machine language
145
099333bc912e More splitups.
roug
parents:
diff changeset
328 level. A detailed description of memory modules and module headers
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
329 can be found in the &quot;NitrOS-9 System Programmer's Manual&quot;.
145
099333bc912e More splitups.
roug
parents:
diff changeset
330 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
331 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
332 Programs can also be explicitly loaded into memory using the
1053
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
333 <command>load</command> command. As with fork, the program will actually be loaded
145
099333bc912e More splitups.
roug
parents:
diff changeset
334 only if it is not already in memory. If the module is not in
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
335 memory, NitrOS-9 will copy a candidate memory module from the file into
145
099333bc912e More splitups.
roug
parents:
diff changeset
336 memory, verify the CRC, and then, if the module is not already in
099333bc912e More splitups.
roug
parents:
diff changeset
337 the module directory, add the module to the directory. This process
099333bc912e More splitups.
roug
parents:
diff changeset
338 is repeated until all the modules in the file are loaded, the 64K
099333bc912e More splitups.
roug
parents:
diff changeset
339 memory limit is exceeded, or until a module with an invalid format
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
340 is encountered. NitrOS-9 always links to the first module read from the
145
099333bc912e More splitups.
roug
parents:
diff changeset
341 file.
099333bc912e More splitups.
roug
parents:
diff changeset
342 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
343 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
344 If the program module <emphasis>is</emphasis> already in memory,
099333bc912e More splitups.
roug
parents:
diff changeset
345 the load will proceed
099333bc912e More splitups.
roug
parents:
diff changeset
346 as described above, loading the module from the specified file,
099333bc912e More splitups.
roug
parents:
diff changeset
347 verifying the CRC, and when attempting to add the valid module to
099333bc912e More splitups.
roug
parents:
diff changeset
348 the module directory, noticing that the module is already known, the
099333bc912e More splitups.
roug
parents:
diff changeset
349 load merely increments the known module's link count (the number of
099333bc912e More splitups.
roug
parents:
diff changeset
350 processes using the module.) The load command can be used to &quot;lock
099333bc912e More splitups.
roug
parents:
diff changeset
351 a program into memory. This can be useful if the same program is to
099333bc912e More splitups.
roug
parents:
diff changeset
352 be used frequently because the program will be kept in memory
099333bc912e More splitups.
roug
parents:
diff changeset
353 continuously, instead of being loaded repeatedly.
099333bc912e More splitups.
roug
parents:
diff changeset
354 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
355 <para>
1053
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
356 The opposite of <command>load</command> is the <command>unlink</command> command, which decreases a
145
099333bc912e More splitups.
roug
parents:
diff changeset
357 program module's link count by one. Recall that when this count becomes zero
099333bc912e More splitups.
roug
parents:
diff changeset
358 (indicating the module in no longer used by any process),
099333bc912e More splitups.
roug
parents:
diff changeset
359 the module is deleted, e.g., its memory is deallocated and its name
1053
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
360 is removed from the module directory. The <command>unlink</command> command is
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
361 generally used in conjunction with the <command>load</command> command (programs
145
099333bc912e More splitups.
roug
parents:
diff changeset
362 loaded by fork are automatically unlinked when the program
099333bc912e More splitups.
roug
parents:
diff changeset
363 terminates).
099333bc912e More splitups.
roug
parents:
diff changeset
364 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
365 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
366 Here is an example of the use of
1053
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
367 <command>load</command> and <command>unlink</command> to lock a
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
368 program in memory. Suppose the <command>copy</command> command will be used five
145
099333bc912e More splitups.
roug
parents:
diff changeset
369 times. Normally, the copy command would be loaded each time the
1053
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
370 <command>copy</command> command is called. If the <command>load</command> command is used first,
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
371 <command>copy</command> will be locked into memory first, for example:
145
099333bc912e More splitups.
roug
parents:
diff changeset
372 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
373 <screen>
099333bc912e More splitups.
roug
parents:
diff changeset
374 OS9: load copy
099333bc912e More splitups.
roug
parents:
diff changeset
375 OS9: copy file1 file1a
099333bc912e More splitups.
roug
parents:
diff changeset
376 OS9: copy file2 file2a
099333bc912e More splitups.
roug
parents:
diff changeset
377 OS9: copy file3 file3a
099333bc912e More splitups.
roug
parents:
diff changeset
378 OS9: unlink copy
099333bc912e More splitups.
roug
parents:
diff changeset
379 </screen>
099333bc912e More splitups.
roug
parents:
diff changeset
380 <para>
1053
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
381 It is important to use the <command>unlink</command> command after the program is no
145
099333bc912e More splitups.
roug
parents:
diff changeset
382 longer needed, or the program will continue to occupy memory which
099333bc912e More splitups.
roug
parents:
diff changeset
383 otherwise could be used for other purposes. Be very careful
099333bc912e More splitups.
roug
parents:
diff changeset
384 <emphasis>not</emphasis> to
099333bc912e More splitups.
roug
parents:
diff changeset
385 completely unlink modules in use by any process! This will cause the
099333bc912e More splitups.
roug
parents:
diff changeset
386 memory used by the module to be deallocated and its contents
099333bc912e More splitups.
roug
parents:
diff changeset
387 destroyed. This will certainly cause all programs using the
099333bc912e More splitups.
roug
parents:
diff changeset
388 unlinked module to crash.
099333bc912e More splitups.
roug
parents:
diff changeset
389 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
390 </section>
099333bc912e More splitups.
roug
parents:
diff changeset
391
1093
4dae346c4969 Added crossreferences and lowercased synopsises
roug
parents: 1053
diff changeset
392 <section id="sec5.4.2">
145
099333bc912e More splitups.
roug
parents:
diff changeset
393 <title>Loading Multiple Programs</title>
099333bc912e More splitups.
roug
parents:
diff changeset
394
099333bc912e More splitups.
roug
parents:
diff changeset
395 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
396 Another important aspect of program loading is the ability to
099333bc912e More splitups.
roug
parents:
diff changeset
397 have two or more programs resident in memory at the same time. This
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
398 is possible because all NitrOS-9 program modules are &quot;position-independent
145
099333bc912e More splitups.
roug
parents:
diff changeset
399 code&quot;, or &quot;PIC&quot;. PIC programs do not have to be loaded into
099333bc912e More splitups.
roug
parents:
diff changeset
400 specific, predetermined memory addresses to work correctly, and can
099333bc912e More splitups.
roug
parents:
diff changeset
401 therefore be loaded at different memory addresses at different
099333bc912e More splitups.
roug
parents:
diff changeset
402 times. PIC programs require special types of machine language instructions
1014
d9ed9d44b70c Some character entities had missing semicolons. It's &CPU;
roug
parents: 1011
diff changeset
403 which few computers have. The ability of the &CPU;
145
099333bc912e More splitups.
roug
parents:
diff changeset
404 microprocessor to use this type of program is one of its most
099333bc912e More splitups.
roug
parents:
diff changeset
405 powerful features.
099333bc912e More splitups.
roug
parents:
diff changeset
406 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
407 <para>
1053
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
408 The <command>load</command> command can therefore be used two or more times (or a
1011
cc153d1671f7 Updated for new manuals
boisy
parents: 145
diff changeset
409 single file may contain several memory modules), and each
145
099333bc912e More splitups.
roug
parents:
diff changeset
410 program module will be automatically loaded at different,
099333bc912e More splitups.
roug
parents:
diff changeset
411 non-overlapping addresses (most other operating systems write over the
099333bc912e More splitups.
roug
parents:
diff changeset
412 previous program's memory whenever a new program is loaded). This
099333bc912e More splitups.
roug
parents:
diff changeset
413 technique also relieves the user from having to be directly concerned with
099333bc912e More splitups.
roug
parents:
diff changeset
414 absolute memory addresses. Any number of program modules
099333bc912e More splitups.
roug
parents:
diff changeset
415 can be loaded until available system memory is full.
099333bc912e More splitups.
roug
parents:
diff changeset
416 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
417 </section>
099333bc912e More splitups.
roug
parents:
diff changeset
418
1093
4dae346c4969 Added crossreferences and lowercased synopsises
roug
parents: 1053
diff changeset
419 <section id="sec5.4.3">
145
099333bc912e More splitups.
roug
parents:
diff changeset
420 <title>Memory Fragmentation</title>
099333bc912e More splitups.
roug
parents:
diff changeset
421
099333bc912e More splitups.
roug
parents:
diff changeset
422 <para>
099333bc912e More splitups.
roug
parents:
diff changeset
423 Even though PIC programs can be initially loaded at any address
099333bc912e More splitups.
roug
parents:
diff changeset
424 where free memory is available, program modules cannot be relocated
099333bc912e More splitups.
roug
parents:
diff changeset
425 dynamically afterwards, e.g., once a program is loaded it must
099333bc912e More splitups.
roug
parents:
diff changeset
426 remain at the address at which it was originally loaded (however
099333bc912e More splitups.
roug
parents:
diff changeset
427 Level Two systems can &quot;load&quot; (map) memory resident programs at
099333bc912e More splitups.
roug
parents:
diff changeset
428 different addresses in each process' address space). This characteristic
099333bc912e More splitups.
roug
parents:
diff changeset
429 can lead to a sometimes troublesome phenomenon called
099333bc912e More splitups.
roug
parents:
diff changeset
430 &quot;memory fragmentation&quot;. When programs are loaded, they are assigned
099333bc912e More splitups.
roug
parents:
diff changeset
431 the first sufficiently large block of memory at the highest address
099333bc912e More splitups.
roug
parents:
diff changeset
432 possible in the address space. If a number of program modules are
099333bc912e More splitups.
roug
parents:
diff changeset
433 loaded, and subsequently one or more modules which are located in
099333bc912e More splitups.
roug
parents:
diff changeset
434 between other modules are &quot;unlinked&quot;, several fragments of free
099333bc912e More splitups.
roug
parents:
diff changeset
435 memory space will exist. The sum of the sizes of the free memory
099333bc912e More splitups.
roug
parents:
diff changeset
436 space may be quite large, but because they are scattered, not enough
099333bc912e More splitups.
roug
parents:
diff changeset
437 space will exist in a single block to load a program module larger
099333bc912e More splitups.
roug
parents:
diff changeset
438 than the largest free space.
099333bc912e More splitups.
roug
parents:
diff changeset
439 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
440 <para>
1053
b5ff125a1d60 Since this book was only typeset in fixed width, single-font, they used
roug
parents: 1014
diff changeset
441 The <command>mfree</command> command shows the location and size of each unused
1500
b00cf13c9f61 Major changes for new NitrOS-9 manual
boisy
parents: 1093
diff changeset
442 memory area and the <command>mdir -e</command> command shows the address, size, and
145
099333bc912e More splitups.
roug
parents:
diff changeset
443 link (use) count of each module in the address space. These
099333bc912e More splitups.
roug
parents:
diff changeset
444 commands can be used to detect fragmentation. Memory can usually be
099333bc912e More splitups.
roug
parents:
diff changeset
445 de-fragmemted by unlinking scattered modules and reloading them.
099333bc912e More splitups.
roug
parents:
diff changeset
446 <emphasis>Make certain</emphasis> none are in use before doing so.
099333bc912e More splitups.
roug
parents:
diff changeset
447 </para>
099333bc912e More splitups.
roug
parents:
diff changeset
448 </section>
099333bc912e More splitups.
roug
parents:
diff changeset
449 </section>
099333bc912e More splitups.
roug
parents:
diff changeset
450 </chapter>