Operating Systems

Download Report

Transcript Operating Systems

Chapter 7
Operating
Systems
©Brooks/Cole, 2003
OBJECTIVES
After reading this chapter, the reader should
be able to:
Define the purpose and functions of an operating system.
Understand the components of an operating system.
Understand the concept of virtual memory.
Understand the concept of deadlock and starvation.
List some of the characteristics of popular operating
systems such as Windows 2000, UNIX, and Linux.
©Brooks/Cole, 2003
Figure 7-1
Computer System
©Brooks/Cole, 2003
7.1
DEFINITION
©Brooks/Cole, 2003
Note:
An operating system is an interface
between the hardware of a computer
and
the user (program or human) that
facilitates(使容易) the execution of
the other programs and the access
to hardware and software resources.
©Brooks/Cole, 2003
7.2
EVOLUTION
©Brooks/Cole, 2003
Evolution-- Batch systems

Batch systems
Each program to be executed was called a job.
 A programmer who wished to execute a job sent
a request to the operating room along with
punched cards for the program and data.
 Operating systems only ensured that all of the
resources were transferred from one job to the
next.

©Brooks/Cole, 2003
Evolution--Time-sharing systems

Multiprogramming



Time sharing


Resource can be shared between different jobs
Scheduling


to hold several jobs in memory
only assign a resource to a job that needs it on the
condition that the resource is available.
OS allocates the resources to different programs and
deciding which program should use which resource
when.
Process

A job is a program to be run, a process is a program that
in memory and waiting for resources.
Evolution (cont.)

Personal systems
Single-user operating systems
 Example: DOS (disk operating system)


Parallel systems


Multiple CPUs on the same machine
Distributed systems

A program can be run partially on one computer
and partially on another computer if they are
connected through an internetwork.
©Brooks/Cole, 2003
7.3
COMPONENTS
©Brooks/Cole, 2003
Figure 7-2
Components of an operating system

A operating system has at least four duties:
memory manager, process manager, device
manager, and file manager.
©Brooks/Cole, 2003
Figure 7-3
Monoprogramming
©Brooks/Cole, 2003
Memory manager (1)

Monoprogramming
OS load a program, run it, and then replace it
with the next program.
 Only one program is in memory for execution.


Problems:
The program must fit in memory.
 When one program is being run, no other
program can be executed.

©Brooks/Cole, 2003
Figure 7-4
Multiprogramming
©Brooks/Cole, 2003
Figure 7-5
Categories of multiprogramming
©Brooks/Cole, 2003
Memory manager (2)

Multiprogramming--Nonswapping

Partitioning (Fig. 7.6)
Memory is divided into variable length sections.
 Each section or partition holds one program.
 The CPU switches between programs


Problems:
The size of the partitions has to be determined
beforehand by the memory manager.
 There may be some holes after programs are
replaced by new ones.

©Brooks/Cole, 2003
Figure 7-6
Partitioning
©Brooks/Cole, 2003
Memory manager (3)

Multiprogramming--Nonswapping

Paging
Paging improves the efficiency of the partitioning.
 Memory is divided into equally sized sections called
frames.
 The program is divided into equally sized sections
called pages.
 Figure 7.7.


Problem: the whole programs still needs to be in
memory before being executed.
©Brooks/Cole, 2003
Figure 7-7
Paging
©Brooks/Cole, 2003
Memory manager (4)

Multiprogramming--Swapping

Demand paging
The program is divided into pages, but the pages can
be loaded into memory one by one, executed, and
replaced by another pages.
 The size of pages are equal.


Demand segmentation

The program is divided into segments (main
program and subprograms) that match the
programmer’s view.
©Brooks/Cole, 2003
Memory manager (5)

Multiprogramming--Swapping

Demand paging and segmentation
A segment may be too large to fit any available free
space in memory.
 Memory can be divided into frames, and a module
can be divided into pages.
 The pages of a module can then be loaded into
memory one by one and executed.

©Brooks/Cole, 2003
Figure 7-8
Virtual memory
©Brooks/Cole, 2003
Process manager

Program


Job


A program is a nonactive set of instructions
written by a programmer and stored on disk.
A program becomes a job from the moment it is
selected for execution until it has finished
running and becomes a program again.
Process

A process is a program in execution.
©Brooks/Cole, 2003
State diagram

State diagram (Fig. 7.9)
Hold state
 Ready state
 Running state
 Waiting stage
 Terminated state

©Brooks/Cole, 2003
Figure 7-9
State diagram with the boundaries
between a program, a job, and a process
Schedulers

Job scheduler


The job scheduler moves a job from the hold
state to the ready state or from the running state
to the terminated state. (Fig. 7.10)
Process scheduler

The process scheduler moves a process from
one state to another. (Fig. 7.11)
©Brooks/Cole, 2003
Figure 7-10
Job scheduler
©Brooks/Cole, 2003
Figure 7-11
Process scheduler
©Brooks/Cole, 2003
Figure 7-12
Queues for process management
©Brooks/Cole, 2003
Queuing

The policies to select the next jog or process:
First in, first out (FIFO) (queue)
 Shortest length first
 The one with highest priority
 And so on ...

©Brooks/Cole, 2003
Process synchronization(同時)

Whenever resources can be used by more
than one processes, you can have two
situations:
Deadlock(死結)
 Starvation(饑餓)

©Brooks/Cole, 2003
Figure 7-13
Deadlock
©Brooks/Cole, 2003
Figure 7-14
Deadlock on a bridge
©Brooks/Cole, 2003
Solutions of deadlock


Deadlock occurs if the OS allows a process
to start running without first checking to see
if the required resources are ready and
allows the process to hold it as long as it
wants.
Solutions of deadlock
Not to allow a process to start running until the
resources are free.
 To limit the time a process can hold a resource.

©Brooks/Cole, 2003
Note:
Deadlock occurs when the
operating system does not put
resource restrictions(限制) on
processes.
©Brooks/Cole, 2003
Four necessary conditions

Four necessary conditions for deadlock:

Mutual exclusion


Resource holding


A process holds a resource even though it cannot use
it until other resources are available.
No preemption(優先權)


Only one process can hold a resource.
The OS cannot temporarily reallocated a resource.
Circular waiting

All process and resources involved form a loop.
©Brooks/Cole, 2003
Figure 7-15.a
Starvation (1)
Figure 7-15.b
Starvation (2)
Figure 7-15.c
Starvation (3)
Figure 7-16
Dining philosophers
Device manager


The device manager is responsible for the
efficient use on input/output devices.
The responsibilities of a device manager:
Monitor every I/O device constantly to assure
that the device is functioning properly.
 Maintains a queue for each I/O device or one or
more queues for similar I/O devices.
 Control the different policies for accessing I/O
devices.

©Brooks/Cole, 2003
File manager

The responsibilities of a file manager:
Control access to files.
 Supervise (監督) the creation, deletion, and
modification of files.
 Control the naming of files.
 Supervise the storage of files.
 Be responsible for archiving (檔案保管) and
backups.

©Brooks/Cole, 2003
User interface


Each OS has a user interface.
Examples:
UNIX  shell
 Windows  window (graphical user interface,
GUI)

©Brooks/Cole, 2003
7.4
POPULAR
OPERATING
SYSTEMS
©Brooks/Cole, 2003
Popular operating systems

Windows 2000


Unix



GUI, virtual memory, multiprogramming, integral
networking capability, security features, …
Portable, powerful set of utilities, device
independent, …
Multiprogramming, virtual memory, well-designed file
and directory systems, and short commands.
Linux

Close to Unix
©Brooks/Cole, 2003
Key terms











Batch operating system
Deadlock
Demand paging
Demand paging and
segmentation
Demand segmentation
Device manager
Distributed system
File manager
Frame
Hold state
Job












Job scheduler
Linux
Memory manager
Monoprogramming
Multiprogramming
Operating system
Page
Paging
Parallel system
Partitioning
Process
Process manager
©Brooks/Cole, 2003










Process scheduler
Process synchronization
Program
Queue
Ready state
Running stage
Multiprogramming
Scheduling
Single-user operating
system
software








Starvation
State diagram
Terminated state
Time sharing
UNIX
User interface
Virtual memory
Waiting state
©Brooks/Cole, 2003