Systems Architecture, Sixth Edition

hungryhorsecabinΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 4 χρόνια και 18 μέρες)

89 εμφανίσεις

Systems Architecture,

Sixth Edition

Chapter 11

Operating Systems

Systems Architecture, Sixth Edition

Chapter Objectives


In this chapter, you will learn to:


Describe the functions and layers of an operating
system


List the resources allocated by the operating
system and describe the allocation process


Explain how an operating system manages
processes and threads

2

Systems Architecture, Sixth Edition

Chapter Objectives (continued)


Compare CPU scheduling methods


Explain how an operating system manages
memory

3

Systems Architecture, Sixth Edition

4

FIGURE 11.1 Topics covered in this chapter

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Operating System Overview


Important part of all information systems


Manages all hardware resources and allocates
them to users and applications as needed


Accesses files and directories, creates and
moves windows, and accesses resources over a
network

5

Systems Architecture, Sixth Edition

Operating System Functions


Functions are divided into five main groups


Resource allocation: ensure that overall system
objectives are achieved efficiently and effectively

6

Systems Architecture, Sixth Edition

7

FIGURE 11.2 OS management functions

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Operating System Layers


Using layers makes the OS easier to maintain


Command layer (shell)


Command language or job control language
(JCL)


Service layer


Service call


Kernel


8

Systems Architecture, Sixth Edition

9

User’s interface to OS

Contains set of
functions executed by
application programs
and command layer

Manages resources;
interacts directly with
computer hardware

FIGURE 11.3 OS layers

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

10

FIGURE 11.4 Components of the kernel

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Resource Allocation


Single
-
tasking and multitasking


Resource allocation tasks


Real and virtual resources

11

Systems Architecture, Sixth Edition

Single
-
Tasking Resource Allocation


Involves only two running programs


Application


OS (grants the application all unused hardware
resources)


Single
-
tasking operating systems are small and
efficient


There’s only one active program


12

Systems Architecture, Sixth Edition

Multitasking Resource Allocation


Norm for modern general
-
purpose computers


Allows flexibility of application and system
software


Resource allocation goals


Meet resource needs of each program


Prevent programs from interfering with one
another


Efficiently use hardware and other resources

13

Systems Architecture, Sixth Edition

Resource Allocation Tasks


Keep detailed records of available resources;
know which resources can satisfy which
requests


Schedule resources based on specific allocation
policies


Update records to reflect resource commitment
and release by programs and users

14

Systems Architecture, Sixth Edition

Real and Virtual Resources


Real resources


Physical devices and associated system software


Virtual resources


Resources that are apparent to a process or user


Meet or exceed real resources by:


Rapidly shifting resources unused by one program
to other programs that need them


Substituting one type of resource for another

15

Systems Architecture, Sixth Edition

Process Management


Process


Unit of executing software managed
independently by OS


Can request and receive hardware resources and
OS services


Can be stand
-
alone or part of a group that
cooperates to achieve a common purpose


Can communicate with other processes executing
on the same computer or on other computers

16

Systems Architecture, Sixth Edition

Process Control Data Structures


Process control block (PCB)


Created, updated, and deleted by OS


Used by OS to perform many functions (e.g.,
resource allocation, secure resource access,
protecting active processes from interference with
other active processes)


Normally organized into a larger data structure
(called a linked list, process queue, or process
list)

17

Systems Architecture, Sixth Edition

Process Control Data Structures
(continued)


Processes can spawn other processes and
communicate with them


Parent process


Child process


Sibling process


Process family

18

Systems Architecture, Sixth Edition

Threads


Portion of a process that can be scheduled and
executed independently


Can execute concurrently on a single processor
or simultaneously on multiple processors


Share all resources allocated to parent process


Advantage: reduce OS overhead for resource
allocation and process management


Thread control block (TCB) and run queues

19

Systems Architecture, Sixth Edition

CPU Allocation


OS makes rapid decisions about which threads
receive CPU control and for how long that
control is retained


Threads usually share CPUs (concurrent or
interleaved execution)

20

Systems Architecture, Sixth Edition

21

FIGURE 11.7 Concurrent (interleaved) thread execution on a single CPU

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Thread States


Ready


Waiting for access to the CPU


Running


Retains control of CPU until the thread or its
parent process terminates normally or an
interrupt occurs


Blocked


Waiting for some event to occur (completion of
service request or correction of an error
condition)

22

Systems Architecture, Sixth Edition

23

FIGURE 11.8 Thread movement between states

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Interrupt Processing


Thread can be blocked waiting for resources


Thread is put into a wait state and its state
stored on the stack


Some interrupt handler will process the blocked
thread’s request


When the resource has been allocated, thread is
moved from block state to ready or running state


The thread remains in the blocked state until the
request is satisfied or a time out occurs

24

Systems Architecture, Sixth Edition

Scheduling


Decision
-
making process used by OS to
determine which ready thread moves to the
running state


Typical methods


Preemptive scheduling


Priority
-
based scheduling


Real
-
time scheduling

25

Systems Architecture, Sixth Edition

Preemptive Scheduling


A thread can be removed involuntarily from the
running state


Functions of the supervisor (portion of OS that
receives control)


Calls appropriate interrupt handler


Transfers control to the scheduler

26

Systems Architecture, Sixth Edition

Preemptive Scheduling (continued)


Functions of the scheduler


Updates status of any process or thread affected
by last interrupt


Decides which thread to dispatch to the CPU


Updates thread control information and the stack
to reflect the scheduling decision


Dispatches selected thread

27

Systems Architecture, Sixth Edition

Preemptive Scheduling (continued)


Processing steps on
left occur after
Thread 1 makes an
I/O service call


Processing steps on
right occur after I/O
device completes I/O
operation

28

FIGURE 11.9 Interrupt processing

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Timer Interrupts


Generated at regular intervals by CPU to give
scheduler an opportunity to suspend currently
executing thread


Not a “real” interrupt


No interrupt handler to call


Supervisor passes control to the scheduler


Important CPU hardware feature for multitasking
OSs

29

Systems Architecture, Sixth Edition

Priority
-
Based Scheduling


Determines which ready thread should be
dispatched to the CPU according to:


First come first served (FCFS)


Explicit priority


Shortest time remaining (STR)

30

Systems Architecture, Sixth Edition

Real
-
Time Scheduling


Guarantees minimum amount of CPU time to a
thread if the thread makes an explicit real
-
time
scheduling request when it is created


Guarantees a thread enough resources to
complete its function within a specified time


Often used in transaction processing, data
acquisition, and automated process control

31

Systems Architecture, Sixth Edition

Memory Allocation


The assignment of specific memory addresses
to system software, application programs, and
data


OS allocates memory


When threads are created; responds to requests
for additional memory during a thread’s lifetime


To itself and for other needs (buffers and caches)

32

Systems Architecture, Sixth Edition

Physical Memory Organization


Main memory can be regarded as a sequence of
contiguous, or adjacent, memory cells


Most significant byte


Least significant byte


Addressable memory


Physical memory

33

Systems Architecture, Sixth Edition

Single
-
Tasking Memory Allocation


Bulk of OS normally occupies lower memory
addresses


Application program is loaded immediately above
it


Contiguous memory allocation


Address resolution


Process of determining physical memory address
that corresponds to memory reference

34

Systems Architecture, Sixth Edition

35

FIGURE 11.13 Contiguous memory allocation in a single
-
tasking OS

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Multitasking Memory Allocation


The operating system:


Finds free memory regions in which to load new
processes and threads


Reclaims memory when processes or threads
terminate

36

Systems Architecture, Sixth Edition

Multitasking Memory Allocation
(continued)


Goals of multitasking memory allocation


Allow as many active processes as possible


Respond quickly to changing memory demands
of processes


Prevent unauthorized changes to a process’s
memory region(s)


Perform memory allocation and addressing as
efficiently as possible

37

Systems Architecture, Sixth Edition

38

FIGURE 11.14 Dividing main memory into fixed
-
size partitions

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

39

FIGURE 11.15 Several processes and the OS loaded into 250 MB
fixed
-
size memory partitions

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

40

TABLE 11.2 Fixed
-
size memory partitions maintained by the OS

Systems Architecture, Sixth Edition

Memory Fragmentation


Occurs when memory partitions allocated to a
single process or purpose are scattered
throughout physical memory


To address the problem


Compaction (large overhead)


Noncontiguous memory allocation

41

Systems Architecture, Sixth Edition

42

FIGURE 11.16 Changes in memory allocation as processes execute
and terminate

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

43

FIGURE 11.17 Compaction combines multiple free space fragments (a) into
a single contiguous partition (b)

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Noncontiguous Memory Allocation


Portions of a process can be allocated to free
partitions anywhere in memory


Uses small fixed
-
sized partitions


More flexible than contiguous memory
allocation, but requires more complex partition
tables and address calculations

44

Systems Architecture, Sixth Edition

45

FIGURE 11.18 Process 6 is allocated to available free
memory partitions

Courtesy of Course Technology/Cengage Learning

Systems Architecture, Sixth Edition

Virtual Memory Management


Allocates portions of processes (pages) to small
memory partitions (page frames)


Swaps pages between memory and secondary
storage as needed


Page hits, page faults, page tables


Page files and victims

46

Systems Architecture, Sixth Edition

47

TABLE 11.3 Portion of a process’s page table

Systems Architecture, Sixth Edition

Memory Protection


Refers to protecting memory allocated to one
program from unauthorized access by another
program


Prevents errors in one program from generating
errors in another


Adds overhead to each write operation

48

Systems Architecture, Sixth Edition

Memory Management Hardware


Complex memory management procedures
incur substantial overhead


Modern CPUs incorporate advanced memory
allocation and address resolution functions in
hardware (e.g., Intel Pentium)

49

Systems Architecture, Sixth Edition

Summary


Operating system overview


Resource allocation


Process management


CPU allocation


Memory allocation

50