-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathProcesses.html
269 lines (242 loc) · 10.3 KB
/
Processes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css"/>
<title>
Processes
</title>
</head>
<body>
<div style="text-align:center">
<p>
<img
src="https://upload.wikimedia.org/wikipedia/commons/b/b1/Htop.png">
</p>
</div>
<h1>
Processes
</h1>
<p>
Why multiple-processes? Check this
<a href="https://gist.github.com/jboner/2841832">
table of latencies.
</a>
We can use the CPU while RAM, disk, and network access are
occurring.
<br>
<br>
Two types of parallelism:
<br>
<b>Pseudo-parallelism:</b> on one CPU, gives the appearance that
processes are running simultaneously.
<br>
<b>Real parallelism:</b> with multiple CPUs, processes
<i>do</i> run simultaneously. (But not <i>all</i> of them,
usually: e.g., four CPUs on my Mac, but 392 processes.)
</p>
<h2>
The Process Model
</h2>
<figure>
<img
src="https://upload.wikimedia.org/wikipedia/commons/0/04/Context_switch.png">
<figcaption>
A context switch
</figcaption>
</figure>
<p>
The illusion of parallelism is produced by continually
switching the CPU between processes. These switches are
expensive.
<br>
<br>
There is no real difference conceptually between what a
single CPU running 100 processes does been a four core CPU
running 400 processes. So here we will just look at the
single CPU situation.
<br>
<br>
It is important to know that from the point of view of a
single program, multiprocessing renders the behavior of the
program nondeterministic. The program cannot be certain how
frequently it will get the CPU. This can become crucial
with programs doing things like playing a video, and
really, really crucial, if the program is monitoring the
state of a nuclear power plant or a patient's vital signs
in the hospital.
<br>
<br>
A process is a program <i>in action</i>.
</p>
<h2>
Process Creation
</h2>
<p>
How processes are created:
</p>
<ol>
<li>System initialization
<li>A running process executes a process-creation system
call.
<li>A user requests a new process.
<li>A batch job starts.
</ol>
<p>
Technically, in <b>all</b> cases, 2 is how new processes
are created.
<br>
<br>
At boot time, a windowing system or command shell may be
started. But the system also starts daemons that listen on
ports for mail or web page requests, scan for viruses,
handle print requests, etc.
<br>
<br>
The book claims that the batch situation only applies on
mainframes. But UNIX has a <b>cron</b> facility for running batch
jobs, and Windows has a <b>Task Scheduler</b>.
<br>
<br>
<b>UNIX:</b> <b>fork</b> and <b>exec</b> pair start process. After fork,
the child is a copy of the parent. It can then manipulate
file handles, and then exec a new program in its process
space.
<br>
<b>Windows:</b> <b>CreateProcess</b> is the single call that
accomplishes both of the above tasks. Win32 has 100 other
calls for managing processes.
</p>
<h2>
Process Termination
</h2>
<p>
How processes terminate:
</p>
<ol>
<li>Normal exit (voluntary)
<li>Error exit (voluntary)
<li>Fatal error exit (involuntary)
<li>Killed by another (involuntary)
</ol>
<p>
Very often, a process and because it has finished its work.
The user clicks "Exit" on a word processor, or a compiler
finishes compiling a program. In UNIX, the process executes
the <b>exit</b> system call, and on Windows,
<b>ExitProcess</b>.
<br>
<br>
The second case is really a special instance of the first:
if we try to compile foo.c and no such file exists, the
compiler exits with the complaint "No such file." but it
may set a different exit code.
<br>
<br>
In the third case, the process has done something naughty,
and the OS kills it: it tried an illegal instruction (e.g.,
switching into kernel mode without executing a system call)
or accessed memory not its own, or dividing by zero.
<br>
<br>
The fourth case is when one process kills another with a
system call and process ID. In UNIX, the call is
<b>kill</b>, and in Windows, <b>TerminateProcess</b>. In
neither case does this kill processes created by the murder
victim. (In some OSes it will.) The murderer needs the
right permissions, e.g., a user process can't kill a kernel
process, and a (non-root) user can't kill the process of
another user.
</p>
<h2>
Process Hierarchies
</h2>
<p>
UNIX processes form a hierarchy: a parent spwans child
processes, which spawn grandchild processes, etc. For
instance, a signal may be sent to the whole process group.
<br>
<br>
Windows has no such process hierarchy.
</p>
<h2>
Process States
</h2>
<figure>
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Process_states.svg/300px-Process_states.svg.png">
<figcaption>
Various process states
</figcaption>
</figure>
<ol>
<li>Running
<li>Ready
<li>Blocked
</ol>
<h2>
Implementation of Processes
</h2>
<p>
In this case, we can usefully turn to the Wikipedia page on
the
<a
href="https://en.wikipedia.org/wiki/Process_control_block">
process control block
</a>.
</p>
<h2>
Modeling Multiprogramming
</h2>
<figure>
<img
src="http://www.cs.nott.ac.uk/~pszgxk/courses/g53ops/images/CPUutilisation.jpg">
<figcaption>
</figcaption>
</figure>
<p>
We look at CPU usage from a probabilistic viewpoint, and
try to see what the <i>likely</i> rate of CPU usage is. We
get a formula, where <i>p</i> is the fraction of time an
average process waits for I/O, and <i>n</i> is the number
of processes:
<br>
<br>
CPU utilization = 1 - <i>p<sup>n</sup></i>
</p>
<h2>
Credits
</h2>
<ul>
<li>List of processes: By PER9000, Per Erik Strandberg -
screenshot of htop running in ubuntu jeos in virtualbox,
then cropped to remove frame., CC BY-SA 3.0,
https://commons.wikimedia.org/w/index.php?curid=3419089
<li>Context switch: By Michael Alexander -
http://www.gearforgaming.com, CC BY-SA 4.0,
https://commons.wikimedia.org/w/index.php?curid=53415227
</ul>
<h2>
External Links
</h2>
<ul>
<li>
<a
href="https://en.wikipedia.org/wiki/Process_(computing)">
Process
</a>
<li>
<a
href="https://www.nayuki.io/page/a-fundamental-introduction-to-x86-assembly-programming#1-tools-and-testing">
Assembly language guide
</a>
<li>
<a href="https://gist.github.com/jboner/2841832">
Latency numbers
</a>
<li>
<a
href="http://www.cs.nott.ac.uk/~pszgxk/courses/g53ops/Memory%20Management/MM02-modelingmulti.html">
Degree of multiprogramming:
</a>
</ul>
</body>
</html>