0% found this document useful (0 votes)
35 views52 pages

Ch02-OS9e

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views52 pages

Ch02-OS9e

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Operating

Systems:
Internals Chapter 2
and Design
Principles Operating System
Overview
Ninth Edition, Global Edition
By William Stallings

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Operating System
◼A program that controls the execution of
application programs
◼ An interface between applications and hardware
Main objectives of an OS:

• Convenience
• Efficiency
• Ability to evolve

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Application programs
Application
programming interface
Application Libraries/utilities Software
binary interface
Operating system
Instruction Set
Architecture
Execution hardware

Memory
System interconnect
translation Hardware
(bus)

I/O devices
Main
and
memory
networking

Figure 2.1 Computer Hardware and Software Structure


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Operating System Services

◼ Program development
◼ Program execution
◼ Access I/O devices
◼ Controlled access to files
◼ System access
◼ Error detection and response
◼ Accounting

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Key Interfaces

◼ Instruction set architecture (ISA)


◼ Application binary interface (ABI)
◼ Application programming interface (API)

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


The Operating System as
Resource Manager
◼ The OS is responsible for controlling
the use of a computer’s resources,
such as I/O, main and secondary
memory, and processor execution
time

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Operating System
as Resource Manager
◼ Functions in the same way as ordinary
computer software
◼ Program, or suite of programs, executed
by the processor
◼ Frequently relinquishes control and must
depend on the processor to allow it to
regain control
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Computer System
I/O Devices
Memory
Operating I/O Controller Printers,
System keyboards,
Software digital camera,
I/O Controller etc.

Programs
and Data

I/O Controller

Processor Processor

Storage
OS
Programs

Data

Figure 2.2 The Operating System as Resource Manager


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Evolution of Operating Systems

▪ A major OS will evolve over time for a


number of reasons:

Hardware upgrades

New types of hardware

New services

Fixes

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Evolution of
Operating Systems
▪ Stages include:

Time
Sharing
Multiprogrammed Systems
Batch Systems
Simple Batch
Systems
Serial
Processing

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Serial Processing
Earliest Computers: Problems:
◼ Scheduling:
◼ No operating system
◼ Most installations used a
◼ Programmers interacted
hardcopy sign-up sheet to
directly with the computer
reserve computer time
hardware
◼ Time allocations could
◼ Computers ran from a console run short or long,
with display lights, toggle resulting in wasted
switches, some form of input computer time
device, and a printer
◼ Setup time
◼ Users have access to the
computer in “series” ◼ A considerable amount of
time was spent on setting up
the program to run
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Simple Batch Systems

◼ Early computers were very expensive


◼ Important to maximize processor utilization

◼ Monitor
◼ User no longer has direct access to processor
◼ Job is submitted to computer operator who batches
them together and places them on an input device
◼ Program branches back to the monitor when finished

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Monitor Point of View
Interrupt
◼ Monitor controls the sequence Processing
Device
of events Monitor
Drivers
Job
Sequencing
◼ Resident Monitor is software Control Language

always in memory Boundary


Interpreter

◼ Monitor reads in job and gives


control User
Program
Area

◼ Job returns control to monitor

Figure 2.3 Memory Layout for a Resident Monitor

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Processor Point of View
◼ Processor executes instruction from the memory
containing the monitor
◼ Executes the instructions in the user program until it
encounters an ending or error condition
◼ “Control is passed to a job” means processor is fetching
and executing instructions in a user program
◼ “Control is returned to the monitor” means that the
processor is fetching and executing instructions from the
monitor program
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Job Control Language
(JCL)
Special type of programming
language used to provide
instructions to the monitor

What compiler to use

What data to use

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Desirable Hardware
Features
Memory protection

• While the user program is executing, it must not alter the memory area
containing the monitor

Timer

• Prevents a job from monopolizing the system

Privileged instructions

• Can only be executed by the monitor

Interrupts

• Gives OS more flexibility in controlling user programs

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Modes of Operation

User Mode Kernel Mode


• User program executes in • Monitor executes in kernel
user mode mode
• Certain areas of memory are • Privileged instructions may
protected from user access be executed
• Certain instructions may not • Protected areas of memory
be executed may be accessed

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Simple Batch System
Overhead
◼ Processor time alternates between execution of user
programs and execution of the monitor
◼ Sacrifices:
◼ Some main memory is now given over to the monitor
◼ Some processor time is consumed by the monitor

◼ Despite overhead, the simple batch system improves


utilization of the computer

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Multiprogrammed
Batch Systems

I/O devices
are slow
compared
to processor

Even with
automatic
job
sequencing

Processor is often
idle

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Read one record from file 15 µs
Execute 100 instructions 1 µs
Write one record to file 15 µs
TOTAL 31 µs

1
Percent CPU Utilization = = 0.032 = 3.2%
31

Figure 2.4 System Utilization Example

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Uniprogramming

Program A Run Wait Run Wait

Time
(a) Uniprogramming

The processor spends a certain amount of time executing, until


Program A
it reachesRun Wait it must Run
an I/O instruction; then wait untilWait
that I/O
instruction concludes before proceeding
Program B Wait Run Wait Run Wait
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Program A Run Wait Run Wait

Multiprogramming Time
(a) Uniprogramming

Program A Run Wait Run Wait

Program B Wait Run Wait Run Wait

Run Run Run Run


Combined Wait Wait
A B A B
Time
(b) Multiprogramming with two programs

◼ There must be enough memory to hold the OS (resident monitor) and one user
Program A
program Run Wait Run Wait

◼ When one job needs to wait for I/O, the processor can switch to the other job, which is
likely not waiting
Program B for I/ORun
Wait Wait Run Wait
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Program B Wait Run Wait Run Wait

Run Run Run Run

Multiprogramming
Combined Wait Wait
A B A B
Time
(b) Multiprogramming with two programs

Program A Run Wait Run Wait

Program B Wait Run Wait Run Wait

Program C Wait Run Wait Run Wait

Run Run Run Run Run Run


Combined Wait Wait
A B C A B C
Time
(c) Multiprogramming with three programs

Figure 2.5 Multiprogramming Example


◼ Also known as multitasking
◼ Memory is expanded to hold three, four, or more programs and switch
among all of them
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Multiprogramming
Example

JOB1 JOB2 JOB3


Type of job Heavy compute Heavy I/O Heavy I/O
Duration 5 min 15 min 10 min
Memory required 50 M 100 M 75 M
Need disk? No No Yes
Need terminal? No Yes No
Need printer? No No Yes

Table 2.1 Sample Program Execution Attributes

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


100% 100%

CPU CPU
0% 0%
100% 100%

Memory Memory
0% 0%
100% 100%

Disk Disk
0% 0%
100% 100%

Terminal Terminal
0% 0%
100% 100%

Printer Printer
0% 0%

Job History Job History JOB1


JOB1 JOB2 JOB3
JOB2
0 5 10 15 20 25 30
minutes JOB3

0 5 10 15
time
minutes
time
(a) Uniprogramming (b) Multiprogramming

Figure 2.6 Utilization Histograms


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Time-Sharing Systems
◼ Can be used to handle multiple interactive jobs
◼ Processor time is shared among multiple users
◼ Multiple users simultaneously access the
system through terminals, with the OS
interleaving the execution of each user
program in a short burst or quantum of
computation

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Batch Multiprogramming Time Sharing
Principal objective Maximize processor use Minimize response time
Source of directives to Job control language Commands entered at the
operating system commands provided with the terminal
job

Table 2.3 Batch Multiprogramming versus Time Sharing

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Compatible Time-Sharing
System (CTSS)
◼ One of the first time-sharing operating systems

◼ Developed at MIT by a group known as Project MAC

◼ The system was first developed for the IBM 709 in 1961

◼ Ran on a computer with 32,000 36-bit words of main memory, with the resident
monitor consuming 5000 of that

◼ Utilized a technique known as time slicing


◼ System clock generated interrupts at a rate of approximately one every 0.2 seconds
◼ At each clock interrupt the OS regained control and could assign the processor to another user
◼ Thus, at regular time intervals the current user would be preempted and another user loaded in
◼ To preserve the old user program status for later resumption, the old user programs and data were
written out to disk before the new user programs and data were read in
◼ Old user program code and data were restored in main memory when that program was next
given a turn
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
0 0 0
Monitor Monitor Monitor
5000 5000 5000
JOB 3
10000
JOB 1
JOB 2
(JOB 2)
20000

Free 25000 25000


Free Free
32000 32000 32000
(a) (b) (c)

0 0 0
Monitor Monitor Monitor
5000 5000 5000
JOB 4
JOB 1
15000 JOB 2
(JOB 1)
20000 20000
(JOB 2) (JOB 2)
25000 25000 25000
Free Free Free
32000 32000 32000
(d) (e) (f)

Figure 2.7 CTSS Operation


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Major Achievements
◼ Operating Systems are among the most
complex pieces of software ever developed
◼ Major advances in development include:
◼ Processes
◼ Memory management
◼ Information protection and security
◼ Scheduling and resource management
◼ System structure

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Process
◼ Fundamental to the structure of operating systems

A process can be defined as:

A program in execution

An instance of a running program


The entity that can be assigned to, and executed on, a processor

A unit of activity characterized by a single sequential thread of execution, a


current state, and an associated set of system resources

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Components of
a Process
◼ A process contains ◼ Theexecution context is
three components: essential:
◼ It is the internal data by
◼ An executable program which the OS is able to
◼ The associated data supervise and control the
process
needed by the program
◼ Includes the contents of the
(variables, work space, various process registers
buffers, etc.) ◼ Includes information such
◼ The execution context as the priority of the process
(or “process state”) of and whether the process is
waiting for the completion
the program of a particular I/O event

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Main Processor
Memory Registers
Process index i

PC

Process
i
Process Base b
list Limit h
j

Management Other
registers

Context
Process
▪ The entire state of the A
Data

Program
process at any instant is (code)
contained in its context
b
▪ New features can be Process
Context

Data
designed and incorporated B h
Program
into the OS by expanding (code)
the context to include any
new information needed to
support the feature
Figure 2.8 Typical Process Implementation
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Causes of Errors
◼ Improper synchronization ◼ Nondeterminate program
◼ It is often the case that a operation
routine must be suspended ◼ When programs share memory,
awaiting an event elsewhere in and their execution is
the system interleaved by the processor,
they may interfere with each
◼ Improper design of the other by overwriting common
signaling mechanism can result memory areas in unpredictable
in loss or duplication ways
◼ The order in which programs
◼ Failed mutual exclusion are scheduled may affect the
◼ More than one user or program outcome of any particular
attempts to make use of a shared program
resource at the same time
◼ There must be some sort of ◼ Deadlocks
mutual exclusion mechanism that ◼ It is possible for two or more
permits only one routine at a time programs to be hung up
to perform an update against the waiting for each other
file
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Memory Management
◼ The OS has five principal storage
management responsibilities:

Automatic
Support of Protection
Process allocation Long-term
modular and access
isolation and storage
programming control
management

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Virtual Memory
◼A facility that allows programs to address
memory from a logical point of view, without
regard to the amount of main memory
physically available
◼ Conceived to meet the requirement of having
multiple user jobs reside in main memory
concurrently

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Paging
◼ Allows processes to be comprised of a number of fixed-
size blocks, called pages
◼ Program references a word by means of a virtual address,
consisting of a page number and an offset within the page

◼ Each page of a process may be located anywhere in main


memory

◼ The paging system provides for a dynamic mapping


between the virtual address used in the program and a
real address (or physical address) in main memory
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
A.1
A.0 A.2
0 0
A.5
1 1
2 2
B.0 B.1 B.2 B.3
3 3
4 4
5 5
6 6
A.7
7 User
A.9
8 program
B
9
A.8
10

User
program
A
B.5 B.6

Main Memory Disk


Main memory consists of a Secondary memory (disk) can
number of fixed-length frames, hold many fixed-length pages. A
each equal to the size of a page. user program consists of some
For a program to execute, some number of pages. Pages for all
or all of its pages must be in programs plus the operating system
main memory. are on disk, as are files.

Figure 2.9 Virtual Memory Concepts


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Real
Memory Address
Processor Management
Virtual Unit
Address Main
Memory

Disk
Address

Secondary
Memory

Figure 2.10 Virtual Memory Addressing


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Information Protection
and Security
◼ The nature of the
threat that concerns
an organization will
Main
vary greatly issues Availability

depending on the
circumstances

◼ The problem involves Authenticity Confidentiality


controlling access to
computer systems
Data
and the information integrity
stored in them

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Scheduling and
Resource Management
◼ Key responsibility of
an OS is managing
Fairness
resources Efficiency

◼ Resource allocation
policies must Differential
consider: responsiveness

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Operating System
Service Call Service
from Process Call
Handler (code)

Long- Short- I/O


Interrupt
Term Term Queues
from Process Interrupt
Queue Queue
Interrupt Handler (code)
from I/O
Short-Term
Scheduler
(code)

Pass Control
to Process

Figure 2.11 Key Elements of an Operating System for Multiprogramming


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Different Architectural
Approaches
◼ Demands on operating systems require new
ways of organizing the OS

Different approaches and design elements have been tried:

• Microkernel architecture
• Multithreading
• Symmetric multiprocessing
• Distributed operating systems
• Object-oriented design

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Microkernel Architecture
◼ Assigns only a few essential functions to the
kernel:
Address Interprocess
Basic
space communication
scheduling
management (IPC)

◼ The approach:

Well suited to a
Simplifies Provides
distributed
implementation flexibility
environment

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Multithreading
Thread Process
◼ Technique in
which a process,
executing an Dispatchable unit of work A collection of one or more
threads and associated
application, is
Program counter, stack
pointer system resources

divided into
threads that can By breaking a single

run concurrently
application into multiple
Includes a processor context threads, a programmer has
and its own data area for a greater control over the
stack modularity of the
application and the timing
of application-related events

Executes sequentially and is


interruptible

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Symmetric
Multiprocessing (SMP)
◼ Term that refers to a computer hardware architecture and also
to the OS behavior that exploits that architecture

◼ The OS of an SMP schedules processes or threads across all


of the processors

◼ The OS must provide tools and functions to exploit the


parallelism in an SMP system

◼ Multithreading and SMP are often discussed together, but the


two are independent facilities

◼ An attractive feature of an SMP is that the existence of


multiple processors is transparent to the user
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
SMP Advantages
More than one process can be
Performance running simultaneously, each on a
different processor

Failure of a single process does not


Availability halt the system

Incremental Performance of a system can be


enhanced by adding an
Growth additional processor

Vendors can offer a range of products


Scaling based on the number of processors
configured in the system
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Time

Process 1

Process 2

Process 3

(a) Interleaving (multiprogramming, one processor)

Process 1

Process 2

Process 3

(b) Interleaving and overlapping (multiprocessing; two processors)

Blocked Running

Figure 2.12 Multiprogramming and Multiprocessing


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
OS Design
Distributed Operating Object-Oriented
System Design

◼ Provides the illusion of a single ◼ Lends discipline to the process


of adding modular extensions to
main memory space and a single
a small kernel
secondary memory space plus
other unified access facilities, such ◼ Enables programmers to
as a distributed file system customize an operating system
without disrupting system
◼ State of the art for distributed integrity
operating systems lags that of
uniprocessor and SMP operating ◼ Also eases the development of
systems distributed tools and full-blown
distributed operating systems

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Questions
1) An __________ is a program that controls the execution of application programs and
acts as an interface between applications and the computer hardware.

2) The portion of the monitor that is always in main memory and available for execution
is referred to as the _________ .
3) __________ is a technique in which a process, executing an application, is divided into
threads that can run concurrently.

4) Two major problems with early serial processing systems were scheduling and __________ .

5) The central idea behind the simple batch-processing scheme is the use of a piece of software
known as the _________ .

6) Any resource allocation and scheduling policy must consider three factors: Fairness,
Differential responsiveness, and __________ .

7) A __________ is set at the beginning of each job to prevent any single job from
monopolizing the system.

8) The OS has five principal storage management responsibilities: process isolation, automatic
allocation and management, support of modular programming, protection and access control,
and __________ .

Copyright © 2018 Pearson Education, Ltd. All Rights


Reserved.
Questions
9) The earliest computers employed __________ processing, a name derived by the way the users
have access to the systems.

10) __________ was designed to keep the processor and I/O devices, including storage devices,
simultaneously busy to achieve maximum efficiency.

11) In a time-sharing, multiprogramming system, multiple users simultaneously access the


system through __________ .

12) The principal objective of __________ is to maximize processor use.

13) Three major lines of computer system development created problems in timing and
synchronization that contributed to the development of the concept of the process:
multiprogramming batch operation, time sharing, and __________ .

14) ___________ is a facility that allows programs to address memory from a logical point of
view, without regard to the amount of main memory physically available.

15) Security and protection as it relates to operating systems is grouped into four categories:
Availability, Data integrity, Authenticity, and __________ .

Copyright © 2018 Pearson Education, Ltd. All Rights


Reserved.
Questions
16) The technique where a system clock generates interrupts, and at each clock interrupt the OS
regains control and assigns the processor to another user, is __________ .

A) time slicing B) multithreading

C) round robin D) clock cycle 16


17) is where the OS must prevent independent processes from interfering with each other's memory, both data and instructions.

A) Support of modular programming B) Process isolation

C) Automatic allocation and management D) Protection and access control


18) A special type of programming language used to provide instructions to the monitor
is __________ .

A) FPL B) JCL
C) DML D) SML

Copyright © 2018 Pearson Education, Ltd. All Rights


Reserved.

You might also like