Learning
World Headquarters
Jones & Bartlett
5 Wall Street
Burlington,
978-443-5000
info@jblearning.com
www.jblearning.com
MA 01803
Jones & Bartlett
contact Jones & Bartlett
www.jblearning.com.
Leaming books and products are available
through most bookstores
Learning directly,
call 800-832-0034,
fax 978-443-8000,
and online booksellers.
or visit our website,
To
discounts
Substantial
professional
associations,
the special sales department
specialsales@jblearning.com.
on bulk quantities of Jones & Bartlett
are available
to corporations,
and other qualified organizations.
and specific discount information, contact
at Jones & Bartlett
Leaming via the above contact information or send an email to
Leaming publications
For details
Copyright
© 2013 by Jones & Bartlett
Leaming, LLC, an Ascend Leaming Company
All rights reserved.
tronic or mechanical,
written permission
from the copyright owner.
No part of the material protected
by this copyright
may be reproduced
in any form, elec
or utilized
storage and retrieval
system, without
including
photocopying,
recording,
or by any information
Credits
Amy Rose
Cathleen Sether
of Production:
Editor: Timothy Anderson
Marketing Manager: Lindsay White
Production
Publisher:
Senior Acquisitions
Managing Editor: Amy Bloom
Director
Associate
Online Products Manager: Dawn Mahon Priest
V.P., Manufacturing
Compositors,
Inc.
Composition:
Cover and Title Page Design: Scott Maden
Cover and Title Page Image: © Rob McKay/ShutterStock,
Printing and Binding: Malloy, Inc.
Cover Printing: Malloy, Inc.
Control: Therese Connell
and Inventory
Northeast
Inc.
Library of Congress Cataloging-in-Publication
Principles
of modem operating systems.
- 2nd ed. I Jose Garrido ... [et al.].
Data
p.cm.
references
Rev. ed. of: Principles of modem operating systems I Jose M. Garrido, Richard
Includes bibliographical
ISBN 978-1-4496-2634-1
1. Operating
QA76.76.063G3844
2012
005 .4' 3---dc22
I. Garrido, Jose M. II. Garrido, Jose M. Principles
systems (Computers)
(casebound)
and index.
Schlesinger.
c2008.
of modem operating
systems.
2011008938
6048
Printed in the United States of America
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Contents
Basic Concepts of Operating Systems 1
1.1 Introduction
1.2 Operating Systems
1.1.1 Software Components
1.2.1 Operating System Interfaces
1.2.2 Multi-Level Views of an Operating System
1.3 Categories of Operating Systems
1.4 Small and Specialized Operating Systems
1.5 Brief History of Operating Systems
1.6 Contemporary Operating Systems
1.7 64-bit Operating Systems
1.6.1 Unix
1.6.2 Microsoft Windows
1.6.3 Mac OS
1.7.1 Microsoft 64-bit Windows 7
1.7.2 Mac OS X
Exercises and Questions
1.8 Summary
Processes and Threads 2
Process States
Process Descriptor
2.1 Introduction
2.2 Processes
2.2.1
2.2.2
2.3 Threads
2.3.1 Multithreading
2.3.2 User-Level Threads
2.3.3 Kernel-Level Threads
2.3.4 Java Threads
1
1
1
2
3
4
7
8
9
10
10
1111
11
12
12
12
13
15
15
15
16
18
19
20
21
22
22
Contents
2.4
2.6
2.5 Multiprogramming
POSIX Threads
Creating POSIX Threads
2.4.1
Basic Synchronization of Pthreads
2.4.2
Scheduling and Priorities of POSIX Threads
2.4.3
CPU and I/O Requests
2.5.1
2.5.2
Interrupting Processes
2.5.3
Context Switch
Summary
Exercises and Questions
Performance Metrics
3.1
3.2 General Concepts of Modeling
3.3
3.4
System Performance and Models 3
Introduction
Simple Models of Computer Systems
Performance of Computer Systems
3.4.1
3.4.2 Workload and System Parameters
Simulation Models
3.5.1
3.5.2
3.5.3
3.6.1
3.6.2
3.6.3
3.6.4
System Capacity and Bottleneck
Summary
Exercises and Questions
Types of Simulation Models
Discrete-Event Models
Stochastic Models
3.6 A Model of the Simple Batch System
Description of the Model
Implementations of the Mode]
Simulation Output of the Console Implementation
Output of the GUI Implementation
3.5
3.7
3.8
4.1
4.2
Systems with Multiprogramming 4
Introduction
Systems with Multiple Stations
CPU and I/O Bursts
4.2.1
4.2.2
Overlapping of CPU and I/O Processing
4.2.3
Context Switches
Studying Systems with Multiprogramming
4.3.1 Model of a System with Multiprogramming
4.3.2 Model of a System Without Multiprogramming
4.3.3
Comparison of the Two Models
4.3
28
29
30
30
31
31
32
33
34
35
37
37
37
38
39
40
41
43
43
44
45
45
46
48
49
56
58
59
60
61
61
61
63
63
64
64
64
68
70
4.4
4.3.4 Models with GUI and Graphical Animation
Summary
Exercises and Questions
Contents
Processor Scheduling 5
5.4 CPU Scheduling Policies
Introduction
5.1
5.2 General Types of Scheduling
Processor Scheduling Concepts
5.3
The CPU Scheduler
5.3.1
5.3.2
Scheduling Multiple Classes of Processes
5.4.1
First-Come-First-Served
Shortest Process Next
5.4.2
5.4.3 Round Robin Scheduling
5.4.4
Shortest Remaining Time
5.4.5 Brief Comparison of the Four Scheduling Policies 114
5.4.6 Dynamic Priority Scheduling
5.4.7 Other Scheduling Policies
Summary
Exercises and Questions
5.5 Multiprocessor Systems
5.6
Synchronization Principles 6
6.1
6.2 Basic Synchronization Principles
6.3 Approaches for Implementing Synchronization
6.4
6.5
Introduction
6.2.1 No Synchronization
6.2.2 Mutual Exclusion
6.2.3
Critical Sections
Semaphores
Synchronization with Semaphores
6.5.1
Critical Section Problem
Event Ordering
6.5.2
Synchronization Case Studies
6.6.1
The Bounded-Buffer Problem
Synchronization with Semaphores in Java
6.6.2
Simulation Models of the Bounded-Buffer Problem 141
6.6.3
6.6.4
The Readers-Writers Problem
Simulation Models of the Readers-Writers Problem 148
6.6.5
POSIX Threads
6.7.1
Creating POSIX Threads
6.6
6.7
71
74
75
77
77
78
78
79
80
80
82
92
98
108
115
116
118
123
124
129
129
129
130
130
130
132
132
134
134
135
136
136
138
146
152
152
Contents
Deadlocks 7
6.9
6.8 Monitors
6.7.2
Basic Synchronization of Pthreads
6.7.3 Mutual Exclusion
6.7.4
Semaphores
6.8.1
Synchronization with Monitors
The Producer-Consumer Problem with a Monitor 157
6.8.2
6.8.3 Monitor Synchronization with Java
6.8.4
Simulation Models Using Monitors
Interprocess Communication
6.9.1 Asynchronous Communication
Simulation Model for Asynchronous Communication 163
6.9.2
Synchronous Communication
6.9.3
6.9.4
Simulation Model for Synchronous Communication 167
6.10 Atomic 'Transactions
6.11 Summary
Exercises and Questions
Resource Allocation Graph
Conditions for the Existence of Deadlock
7.1
7.2 Basic Principles of Deadlock
Introduction
7.2.1
7.2.2
The Dining Philosophers
7.3.1 Modeling Deadlock
7.3.2
7.3
7.4 Methods for Handling Deadlock
7.5 Deadlock Prevention
Informal Solution to Deadlock
7.6 Deadlock Avoidance
Banker’s Algorithm
7.5.1 Disallowing Hold and Wait
7.5.2 Disallowing Circular Wait
7.5.3 Model with Graphical Animation
7.6.1
7.6.2 Applying the Banker’s Algorithm
7.7.1 Deadlock Detection
7.7.2
Summary
Exercises and Questions
Recovery
7.7 Deadlock Detection and Recovery
7.8
File Management 8
8.1
Introduction
153
154
155
156
156
158
160
162
162
166
170
172
173
175
175
175
177
178
181
182
185
188
189
189
194
198
201
201
201
203
203
204
205
205
207
207
8.2
8.3
8.4
8.5
8.6
8.7
8.8
8.9
8.10
Files
File Attributes
8.2.1
8.2.2
Folders
Pathnames
8.2.3
Access Methods
Open
8.3.1
Close
8.3.2
8.3.3
Read
Write
8.3.4
8.3.5
Sequential Access
8.3.6
Streams, Pipes, and I/O Redirection
8.3.7
Other I/O System Calls
Directory Functions
File Space Allocation
8.5.1
8.5.2
8.5.3
8.5.4
8.5.5
Real-World Systems
8.6.1
8.6.2
8.6.3
8.6.4
8.6.5
Virtual FUe System
Removable Media
Seeing the Future Now
Summary
Exercises and Questions
Cluster Allocation
Calculating Read/Write Addresses
Free Space Management
Disk Fragmentation
Reliability of Disk Space Management
Microsoft FAT System
Microsoft NTFS System
Linux Ext2 and Ext3 Systems
Mac OS X HFS+ Systems
Other File Systems
The I/O System 9
9.1 Introduction
9.2 I/O Hardware
9.2.1 Direct Memory Access
9.2.2 Hard Disk Drives
9.2.3
Solid State Disks
9.3.1 Intelligent Buses
9.3.2 Handling Multiple Devices Simultaneously
9.3 Device I/O Structure
9.4 I/O Performance Optimization
207
208
209
209
211
211
212
213
214
215
215
217
217
217
218
219
220
221
222
222
223
225
226
227
228
228
229
231
231
232
233
233
233
235
237
238
238
241
243
244
Contents
9.4.1 Reducing the Number of I/O Requests
9.4.2 Buffering and Caching
9.4.3 I/O Scheduling
9.5 Hard Disk I/O Scheduling
9.5.1 First-Come First-Served Algorithm
9.5.2 Shortest Seek Time First Algorithm
9.5.3 Elevator (SCAN) Algorithm
9.5.4 Circular Scan Algorithm
9.5.5 Optimizing Rotational Latency
9.5.6 Interaction of Disk Scheduling and Other System
Functions
9.6 System Configuration
9.7 Hard Disk Scheduling Simulation Model
9.8 Summary
Exercises and Questions
Memory Management 10
10.1 Introduction
10.2 Process Address Space
10.3 Contiguous Memory Allocation
10.4 Noncontiguous Memory Allocation
10.2.1 Binding
10.2.2 Static and Dynamic Loading
10.2.3 Static and Dynamic Linking
10.3.1 Fixed Partitions
10.3.2 Dynamic Partitions
10.3.3 Swapping
10.4.1 Paging
10.4.2 Segmentation
10.5 Virtual Memory
10.5.1 Basic Concepts
10.5.2 Process Locality
10.5.3 Using Segments
10.5.4 Memory Protection
10.5.5 Shared Memory
10.5.6 Address Translation
10.5.7 Page Size Considerations
10.6 Paging with Virtual Memory
10.6.1 Paging Policies
10.6.2 Frame Allocation
10.6.3 Page Faults and Performance Issues
245
245
248
248
249
249
250
251
251
252
252
254
257
257
259
259
260
261
262
262
262
263
264
267
268
268
271
272
273
273
275
275
276
277
278
278
279
281
281