-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy path9Exercises.html
More file actions
480 lines (448 loc) · 20.4 KB
/
Copy path9Exercises.html
File metadata and controls
480 lines (448 loc) · 20.4 KB
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<!DOCTYPE html>
<html lang="en"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<title>Angold-4 Organization</title>
<!-- Using the latest rendering mode for IE -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../../../images/favicon.png" rel="icon">
<link rel="canonical" href=".">
<meta name="author" content="Angold Wang" />
<meta property="og:site_name" content="Angold-4" />
<!-- <meta property="og:type" content="article"/> -->
<meta property="og:title" content="Angold-4 Organization"/>
<meta property="og:url" content="."/>
<!-- Bootstrap -->
<link rel="stylesheet" href="../../../theme/css/bootstrap.flatly.min.css" type="text/css"/>
<link href="../../../theme/css/font-awesome.min.css" rel="stylesheet">
<!-- <link href="https://cdnjs.cloudflare.com/ajax/libs/typicons/2.0.9/typicons.min.css" rel="stylesheet"> -->
<link href="../../../theme/css/pygments/monokai.css" rel="stylesheet">
<link rel="stylesheet" href="../../../theme/css/style.css" type="text/css"/>
<style>
#TOC li {
list-style: none;
}
#TOC ul {
padding-left: 1.3em;
}
#TOC > ul {
padding-left: 0;
}
#TOC a:not(:hover) {
text-decoration: none;
}
li {
font-size: 18px;
}
p {
font-size: 18px;
}
a {
font-size: 18px;
}
k
code {
font-family: Menlo, Monaco, 'Lucida Console', Consolas, monospace;
font-size: 85%;
margin: 0;
}
pre {
margin: 1em 0;
overflow: auto;
}
pre code {
padding: 0;
overflow: visible;
overflow-wrap: normal;
}
.sourceCode {
background-color: transparent;
overflow: visible;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script> -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="http://angold4.org" class="navbar-brand">
<img src="../../../images/logo.png" width="32"/> Angold4 </a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li><a href="../../../about.html">About</a>
<li><a href="../../../blogs.html">Blogs</a>
<li><a href="../../../projects.html">Projects</a>
</ul>
<ul class="nav navbar-nav navbar-right">
<li> <a title="Youtube" href="https://www.youtube.com/channel/UC3ZAjh2LHhm-FrgxgBtgMzQ" target="_new"><i class="fa fa-youtube"></i> Youtube</a>
</li>
</div>
<!-- /.navbar-collapse -->
</div>
</div> <!-- /.navbar -->
<div class="container">
<div class="row">
<div class="col-lg-12">
<section id="content" class="body">
<nav id="TOC" role="doc-toc">
<ul>
<li><a href="#operating-systerms-design-and-implementation-notes"
id="toc-operating-systerms-design-and-implementation-notes">Operating
Systerms Design and Implementation Notes</a></li>
<li><a href="#exercises-for-chapter-1"
id="toc-exercises-for-chapter-1">9. Exercises for Chapter 1</a>
<ul>
<li><a href="#question1" id="toc-question1">Question1</a></li>
<li><a href="#question2" id="toc-question2">Question2</a></li>
<li><a href="#question3" id="toc-question3">Question3</a></li>
<li><a href="#question4" id="toc-question4">Question4</a></li>
<li><a href="#question5" id="toc-question5">Question5</a></li>
<li><a href="#question6" id="toc-question6">Question6</a></li>
<li><a href="#question7" id="toc-question7">Question7</a></li>
<li><a href="#question8" id="toc-question8">Question8</a></li>
<li><a href="#question9" id="toc-question9">Question9</a></li>
<li><a href="#question10" id="toc-question10">Question10</a></li>
<li><a href="#question11" id="toc-question11">Question11</a></li>
<li><a href="#question12" id="toc-question12">Question12</a></li>
<li><a href="#question13" id="toc-question13">Question13</a></li>
<li><a href="#question14" id="toc-question14">Question14</a></li>
<li><a href="#question15" id="toc-question15">Question15</a></li>
<li><a href="#question16" id="toc-question16">Question16</a></li>
</ul></li>
</ul>
</nav>
<h3 id="operating-systerms-design-and-implementation-notes">Operating
Systerms Design and Implementation Notes</h3>
<h5 id="by-jiawei-wang">By Jiawei Wang</h5>
<h1 id="exercises-for-chapter-1">9. Exercises for Chapter 1</h1>
<p><br></p>
<h3 id="question1">Question1</h3>
<blockquote>
<p><strong>What are the two main functions of an operating
system?</strong><br></p>
</blockquote>
<ol type="1">
<li><strong>Provide the users with an extended (i.e., virtual)
machine</strong></li>
<li><strong>Manage the I/O devices and other system
resources.</strong></li>
</ol>
<h3 id="question2">Question2</h3>
<blockquote>
<p><strong>What is the difference between kernel mode and user mode?
<br>Why is the difference important to an operating system?</strong></p>
</blockquote>
<p><strong>In kernel mode, every machine instruction is allowed, as is
access to all the I/O devices. In user mode, many sensitive instructions
are prohibited.</strong><br> <strong>Operating systems use these two
modes to encapsulate user programs. Running user programs in user mode
keeps them from doing I/O and prevents them from interfering with each
other and with the kernel.</strong></p>
<h3 id="question3">Question3</h3>
<blockquote>
<p><strong>What is multiprogramming?</strong></p>
</blockquote>
<p><strong>Multiprogramming is the rapid switching of the CPU between
multiple processes in memory. It is commonly used to keep the CPU busy
while one or more processes are doing I/O.</strong></p>
<h3 id="question4">Question4</h3>
<blockquote>
<p><strong>What is spooling? Do you think that advanced personal
computers will have spooling as a standard feature in the
future?</strong></p>
</blockquote>
<p><strong>First Please check the <a
href="https://en.wikipedia.org/wiki/Spooling">Spooling</a>.it is to use
software to simulate offline technology</strong><br> <strong>the “Spool”
stands for Simultaneous Peripheral Operations On-Line, which I’ve be
metioned in the history of OS.</strong><br></p>
<ul>
<li><strong><u>Input spooling</u> is the technique of reading in jobs,
for example, from cards, onto the disk, so that when the currently
executing processes are finished, there will be work waiting for the
CPU.</strong></li>
<li><strong><u>Output spooling</u> consists of first copying printable
files to disk before printing them, rather than printing directly as the
output is generated</strong> <br></li>
</ul>
<p><strong>Input spooling on a personal computer is not very likely, but
output spooling is widely used in nowadays computers.</strong></p>
<h3 id="question5">Question5</h3>
<blockquote>
<p><strong>On early computers, every byte of data read or written was
directly handled by the CPU (i.e., there was no DMA—Direct Memory
Access). What implications does this organization have for
multiprogramming?</strong></p>
</blockquote>
<p><strong>The DMA(Direct Memory Access):<br>First, In early CPU, when
data from I/O wants to access the memory, it need to go through the CPU
then to the Memory.</strong><br> <strong>This bring these actions not
very effecient. By using DMA, which means add a DMA Controller between
I/O and Memory and the CPU don’t need to wait while sending the
data:<br></strong></p>
<p><img src="Sources/DMA.png" alt="DMA" /> <br></p>
<p><strong>The prime reason for multiprogramming is to give the CPU
something to do while waiting for I/O to complete. If there is no DMA,
the CPU is fully occupied doing I/O, so there is nothing to be gained
(at least in terms of CPU utilization) by multiprogramming.</strong></p>
<h3 id="question6">Question6</h3>
<blockquote>
<p><strong>List some differences between personal computer operating
systems and mainframe operating systems.</strong></p>
</blockquote>
<ul>
<li><strong>Personal computer systems are always interactive, often with
only a single user.</strong></li>
<li><strong>Mainframe systems nearly always emphasize batch or
timesharing with many users</strong></li>
<li><strong>On Mainframe systems: Protection is much more a issue as
well as the efficient use of all resources</strong></li>
</ul>
<h3 id="question7">Question7</h3>
<blockquote>
<p><strong>Give one reason why a closed-source proprietary operating
system like Windows should have better quality than an open-source
operating system like Linux. Now give one reason why an open-source
operating system like Linux should have better quality than a
closed-source proprietary operating system like Windows.</strong></p>
</blockquote>
<ul>
<li><p><strong>Closed Source: Company can vet the programmers, establish
programming standards, and enforce a development and testing
methodology, also the Closed Source means can help to protect the core
technology for big company</strong></p></li>
<li><p><strong>Open Source: more people look at the code, so there is a
form of peer review and the odds of a bug slipping in are much smaller
with so much more inspection.</strong></p></li>
</ul>
<h3 id="question8">Question8</h3>
<blockquote>
<p><strong>In view of the fact that the mere existence of a superuser
can lead to all kinds of security problems, why does such a concept
exist?</strong></p>
</blockquote>
<p><strong>It is often essential to have someone who can do things that
are normally forbidden. For example, a user starts up a job that
generates an infinite amount of output. The user then logs out and goes
on a three-week vacation to London. Sooner or later the disk will fill
up, and the superuser will have to manu- ally kill the process and
remove the output file. Many other such examples exist.</strong></p>
<h3 id="question9">Question9</h3>
<blockquote>
<p><strong>Why is the process table needed in a timesharing system? Is
it also needed in personal computer systems in which only one process
exists, that process taking over the entire machine until it is
finished?</strong></p>
</blockquote>
<p><strong>The process table is needed to store the state of a process
that is currently suspended, either ready or blocked. It is not needed
in a single process system because the single process is never
suspended.</strong></p>
<h3 id="question10">Question10</h3>
<blockquote>
<p><strong>What is the essential difference between a block special file
and a character special file?</strong></p>
</blockquote>
<p><strong>Block special files consist of numbered blocks, each of which
can be read or written independently of all the other ones. It is
possible to seek to any block and start reading or writing. This is not
possible with character special files.</strong></p>
<p><strong>The name “block device” comes from the fact that the
corresponding hardware typically reads and writes a whole block at a
time</strong><br></p>
<p><strong>The name “character device” comes from the fact that each
character is handled individually. Writing a byte to a character device
might cause it to be displayed on screen, output on a serial port,
converted into a sound, …<br></strong></p>
<p><strong>For more, see <a
href="https://unix.stackexchange.com/questions/60034/what-are-character-special-and-block-special-files-in-a-unix-system">Unix.stackexchange.com</a>:<br></strong></p>
<h3 id="question11">Question11</h3>
<blockquote>
<p><strong>In MINIX 3 if user 2 links to a file owned by user 1, then
user 1 removes the file, what happens when user 2 tries to read the
file?</strong></p>
</blockquote>
<p><strong>The read works normally. User 2’s directory entry contains a
pointer (fd) to the i-node of the file, and the reference count in the
i-node was incremented when user 2 linked to it. So the reference count
will be nonzero and the file itself will not be removed when user 1
removes his directory entry for it. Only when all directory entries for
a file have been removed will its i-node and data actually
vanish.</strong></p>
<h3 id="question12">Question12</h3>
<blockquote>
<p><strong>Are pipes an essential facility? Would major functionality be
lost if they were not available?</strong></p>
</blockquote>
<p><strong>No, they are not so essential. In the absence of pipes,
program 1 could write its output to a file and program 2 could read the
file. While this is less efficient than using a pipe between them, and
uses unnecessary disk space, in most circumstances it would work
adequately.</strong><br> <strong>If you want to see the difference
between pipe and file. Please check this <a
href="https://github.com/Angold-4/OSDI/blob/master/Chapters/Chapter1/6Syscall-2.md#pipe----create-pipe">Note</a>.</strong></p>
<h3 id="question13">Question13</h3>
<blockquote>
<p><strong>Windows does not have a <code>fork()</code> system call, yet
it is able to create new processes. Make an educated guess about the
semantics of the system call Windows uses to create new
processes.</strong></p>
</blockquote>
<p><strong>Windows has a call <code>spawn()</code> that creates a new
process and starts a specific program in it. It is effectively a
combination of <code>fork()</code> and <code>exec()</code>.</strong></p>
<h3 id="question14">Question14</h3>
<blockquote>
<p><strong>Why is the chroot system call limited to the
superuser?</strong></p>
</blockquote>
<p><strong>If an ordinary user could set the root directory anywhere in
the tree, he could create a file etc/passwd in his home directory, and
then make that the root directory. He could then execute some command,
such as su or login that reads the password file, and trick the system
into using his password file, instead of the real one.</strong></p>
<h3 id="question15">Question15</h3>
<blockquote>
<p><strong>Why does MINIX 3 have the program update running in the
background all the time?</strong></p>
</blockquote>
<p><strong>When a user program writes on a file, the data does not
really go to the disk. It goes to the buffer cache(not fast enough). The
update program issues SYNC calls every 30 seconds to force the dirty
blocks in the cache onto the disk, in order to limit the potential
damage that a system crash could cause.</strong></p>
<h3 id="question16">Question16</h3>
<blockquote>
<p><strong>In this Chapter1, we learned many System Calls in Minix3.
Which call do you think is likely to execute most quickly. Explain your
answer.</strong></p>
</blockquote>
<p><strong>The getpid, getuid, getgid, and getpgrp, calls just extract a
word from the pro- cess table and return it. They will execute very
quickly. They are all equally fast.</strong></p>
</section>
</div>
</div>
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = "https://angold4.org/OSDI/Chapter/Chapter1/9Exercises.html"
this.page.identifier = "OSDI/Chapter/Chapter1/9Exercises.html"
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://angold.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
<footer>
<div class="well well-lg" id="footer-well">
<div class="container">
<div class="row">
<div class="col-xs-6">
<a href="https://angold4.org" title="Angold-4 Organization" class="image-link"><img src="../../../images/logo.png" class="cmudb-logo" /></a>
</div>
<div class="col-xs-6">
<p class="pull-right"><i class="fa fa-arrow-up"></i> <a href="#">Back to top</a></p>
</div>
</div>
</div>
</div>
</footer>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="../../../theme/js/bootstrap.min.js"></script>
<!-- Enable responsive features in IE8 with Respond.js (https://github.com/scottjehl/Respond) -->
<script src="../../../theme/js/respond.min.js"></script>
<!-- Fix scrolling issues to internal HREFs that get positioned behind navbar -->
<!-- http://stackoverflow.com/questions/10732690/offsetting-an-html-anchor-to-adjust-for-fixed-header -->
<script src="../../../theme/js/href_scroll.js"></script>
<!-- You know what this is and you know what he did to me... -->
<script src="../../../theme/js/tim-kraska-betrayed-me.js"></script>
</body>
</html>