Chapter 6 Powerpoints

Download Report

Transcript Chapter 6 Powerpoints

Chapter 6: An Introduction
to System Software and
Virtual Machines
Invitation to Computer Science,
C++ Version, Third Edition
Objectives
In this chapter, you will learn about:

System software

Assemblers and assembly language

Operating systems
Invitation to Computer Science, C++ Version, Third Edition
2
Introduction

Von Neumann computer


“Naked machine”

Hardware without any helpful user-oriented
features

Extremely difficult for a human to work with
An interface between the user and the hardware
is needed to make a Von Neumann computer
usable
Invitation to Computer Science, C++ Version, Third Edition
3
Introduction (continued)

Tasks of the interface

Hide details of the underlying hardware from the
user

Present information in a way that does not require
in-depth knowledge of the internal structure of the
system
Invitation to Computer Science, C++ Version, Third Edition
4
Introduction (continued)

Tasks of the interface (continued)

Allow easy user access to the available resources

Prevent accidental or intentional damage to
hardware, programs, and data
Invitation to Computer Science, C++ Version, Third Edition
5
System Software: The Virtual Machine


System software

Acts as an intermediary between users and
hardware

Creates a virtual environment for the user that
hides the actual computer architecture
Virtual machine (or virtual environment)

Set of services and resources created by the
system software and seen by the user
Invitation to Computer Science, C++ Version, Third Edition
6
Figure 6.1
The Role of System Software
Invitation to Computer Science, C++ Version, Third Edition
7
Types of System Software

System software is a collection of many different
programs

Operating system

Controls the overall operation of the computer

Communicates with the user

Determines what the user wants

Activates system programs, applications
packages, or user programs to carry out user
requests
Invitation to Computer Science, C++ Version, Third Edition
8
Figure 6.2
Types of System Software
Invitation to Computer Science, C++ Version, Third Edition
9
Types of System Software (continued)

User interface


Graphical user interface (GUI) provides graphical
control of the capabilities and services of the
computer
Language services

Assemblers, compilers, and interpreters

Allow you to write programs in a high-level, useroriented language, and then execute them
Invitation to Computer Science, C++ Version, Third Edition
10
Types of System Software (continued)

Memory managers


Information managers


Allocate and retrieve memory space
Handle the organization, storage, and retrieval of
information on mass storage devices
I/O systems

Allow the use of different types of input and output
devices
Invitation to Computer Science, C++ Version, Third Edition
11
Types of System Software (continued)

Scheduler


Keeps a list of programs ready to run and selects
the one that will execute next
Utilities

Collections of library routines that provide services
either to user or other system routines
Invitation to Computer Science, C++ Version, Third Edition
12
Programming Languages
Figure 6.3
The Continuum of Programming Languages
•System software provides compilers or interpreters for high level languages.
•Also provides assemblers as a low-level language service
Invitation to Computer Science, C++ Version, Third Edition
13
Assembly Language

Assembly languages

Designed to overcome shortcomings of machine
languages

Create a more productive, user-oriented
environment

Earlier termed second-generation languages

Now viewed as low-level programming languages
Invitation to Computer Science, C++ Version, Third Edition
14
Assemblers and Assembly Language:
Machine Language vs Assembly Language

Machine language

Uses binary

Allows only numeric memory addresses

Difficult to change

Difficult to create data
Invitation to Computer Science, C++ Version, Third Edition
15
Assemblers and Assembly Language:
Machine Language vs Assembly Language

Assembly Language

Uses symbolic operation codes rather than
numeric (binary) ones

Uses symbolic memory addresses rather than
numeric (binary) ones

Has pseudo-operations that provide useful useroriented services such as data generation
Invitation to Computer Science, C++ Version, Third Edition
16
Using Assembly Language to Develop Software

Source program


Object program


An assembly language program
A machine language program
Assembler

Translates a source program into a corresponding
object program
Invitation to Computer Science, C++ Version, Third Edition
17
Figure 6.4
The Translation/Loading/Execution Process
Invitation to Computer Science, C++ Version, Third Edition
18
Examples of Assembly Language Code
A=B+C–7

Arithmetic expression:

(Assume that B and C have already been
assigned values)
Load B
Add C
Invitation to Computer Science, C++ Version, Third Edition
Sub 7
Store A
19
Label
OpCode
Address
Comment
.BEGIN
LOAD
B
--Put CON(B) into register R
ADD
C
--R now holds the sum (B+C)
SUBTRACT
SEVEN
--R now holds value (B + C – 7)
STORE
A
--Store CON(R) into A
HALT
A:
.DATA
0
-- intialize data item A to 0
B:
.DATA
0
-- initialize data item B to 0
C:
.DATA
0
-- initialize data item C to 0
SEVEN:
.DATA
7
-- initialize data item SEVEN to 7
.END
Invitation to Computer Science, C++ Version, Third Edition
20
Assembly Language Example #2
.BEGIN
-- start of the program
-- Input X
-- Input Y
Get the value of x
Get the value of y
IN
IN
If x > y then
Print the value of x
LOAD Y
-- Load Y into register R
COMPARE X
-- Compare X to Y
JUMPGT PRINTX -- Jump if X > Y
Else
Print the value of y
X
Y
OUT Y
JUMP DONE
PRINTX: OUT
DONE: HALT
X: .DATA
Y: .DATA
.END
Invitation to Computer Science, C++ Version, Third Edition
X
-- Didn't jump so print Y
-- and go to end
-- X > Y so print X
-– Stop
0
0
-- end of the program
21
Assembly Language Example # 3

Problem

Read in a sequence of non-negative numbers,
one number at a time, and compute a running
sum

When you encounter a negative number, print out
the sum of the non-negative values and stop
Invitation to Computer Science, C++ Version, Third Edition
22
Figure 6.7
Algorithm to Compute the Sum of Numbers
•Assembly language has no ‘while’ statement
•Need to rewrite before converting to assembly language
Invitation to Computer Science, C++ Version, Third Edition
23
Assembly Language Example 3 cont’d.
1.
2.
3.
4.
5.
6.
7.
8.
Set the value of Sum to 0
Get the value of N
If ( n < 0) GoTo Step 7
Set the value of Sum to Sum + N
Get the value of N
GoTo Step 3
Print the value of Sum
Stop
Invitation to Computer Science, C++ Version, Third Edition
24
Figure 6.8 Assembly Language Program to
Compute the Sum of Nonnegative Numbers
Translation and Loading

Before a source program can be run, an
assembler and a loader must be invoked

Assembler


Translates a symbolic assembly language
program into machine language
Loader

Reads instructions from the object file and stores
them into memory for execution
Invitation to Computer Science, C++ Version, Third Edition
26
Translation and Loading (continued)

Assembler tasks

Convert symbolic op codes to binary

Convert symbolic addresses to binary

Perform assembler services requested by the
pseudo-ops

Put translated instructions into a file for future use
Invitation to Computer Science, C++ Version, Third Edition
27
Pass 1 of Assembler Builds a Symbol Table
.BEGIN
-- start of the program
-- Input X
-- Input Y
0
1
IN
IN
2
3
4
LOAD Y
-- Load Y into register R
COMPARE X
-- Compare X to Y
JUMPGT PRINTX -- Jump if X > Y
5
6
OUT Y
JUMP DONE
7
X
Y
PRINTX: OUTX
8
DONE: HALT
9
X: .DATA
10
Y: .DATA
.END
-- Didn't jump so print Y
-- and go to end
-- X > Y so print X
-– Stop
Symbol Table
Symbol
Address
PRINTX
..0111 (7)
DONE
..1000 (8)
X
..1001 (9)
Y
..1010 (10)
0
0
-- end of the program
Invitation to Computer Science, C++ Version, Third Edition
28
Pass 2 of Assembler Builds an Object File
.BEGIN
PRINTX:
DONE:
X:
Y:
.END
IN
X
IN
Y
LOAD Y
COMPARE X
JUMPGT PRINTX
OUT Y
JUMP DONE
OUTX
HALT
.DATA 0
.DATA 0
Symbol
Address
PRINTX
0000 0000 0111
(7)
DONE
0000 0000 1000
(8)
X
0000 0000 1001
(9)
Y
0000 0000 1010
(10)
Invitation to Computer Science, C++ Version, Third Edition
more_lines = ‘T’
While (more_lines) do
Read the next instruction, instr
If (instr = ‘.END’)
{more_lines = ‘F’}
Else If (instr = ‘.DATA’)
process it
Else
look up opcode in table;
look up address in symbol table;
build instruction
append instruction to object file
Endif
Endwhile
Write file to disk
Stop
IN X  1101 0000 0000 1001
IN Y  1101 0000 0000 1010
…
JUMP DONE  1000 0000 0000 1000
29
Assembler: Performance Considerations
Pass 2 – Tasks for each line of source code

1.
2.
3.
Convert symbolic opcode to numeric opcode
- Table lookup
Convert symbolic address to numeric opcode
- Table lookup
Concatenate numeric address with numeric opcode
What if 100s of opcodes and 100,000 lines of code?
Store symbol table in binary search tree
Invitation to Computer Science, C++ Version, Third Edition
30
Binary Search Tree for Opcodes
To make pass 1 of the assembler more efficient, alphabetize
the symbolic opcodes, so they can be located using binary
search. See binary search tree below.
Invitation to Computer Science, C++ Version, Third Edition
31
Invitation to Computer Science, C++ Version, Third Edition
32
Pass 2 of assembler
Operating Systems

System commands

Carry out services such as translate a program,
load a program, run a program

Types of system commands


Lines of text typed at a terminal

Menu items displayed on a screen and selected
with a mouse and a button: point-and-click
Examined by the operating system
Invitation to Computer Science, C++ Version, Third Edition
34
Functions of an Operating System

Five most important responsibilities of the
operating system

User interface management

Program scheduling and activation

Control of access to system and files

Efficient resource allocation

Deadlock detection and error detection
Invitation to Computer Science, C++ Version, Third Edition
35
The User Interface


Operating system

Waits for a user command

If command is legal, activates and schedules the
appropriate software package
User interfaces

Text-oriented

Graphical
Invitation to Computer Science, C++ Version, Third Edition
36
Figure 6.15
User Interface
Responsibility of the
Operating System
Invitation to Computer Science, C++ Version, Third Edition
37
Text Oriented Interface (CLI)
[durand@neptune ~]$ grep 'cout' array2.cpp | sort
cout << arr[i] << '\n';
cout << arr[i] << '\n';
cout << "\n";
cout << "\nArray contents:\n";
cout << "\nArray contents:\n";
using std::cout;
[durand@neptune ~]$
Invitation to Computer Science, C++ Version, Third Edition
38
Graphical User Interface (GUI)
Invitation to Computer Science, C++ Version, Third Edition
39
System Security And Protection

The operating system must prevent

Non-authorized people from using the computer


User names and passwords
Legitimate users from accessing data or programs
they are not authorized to access

Authorization lists
Invitation to Computer Science, C++ Version, Third Edition
40
UNIX – User IDs & Passwords

Every person who uses a UNIX computer should have an account.

An account is identified by a username.

Traditionally, each account also has a secret password associated
with it to prevent unauthorized use.

You need to know both your username and your password to log
into a UNIX system.

The username is an identifier: it tells the computer who you are.

The password is an authenticator: you use it to prove to the
operating system that you are who you claim to be.
Invitation to Computer Science, C++ Version, Third Edition
41
UNIX – User IDs & Passwords Cont’d.

Standard UNIX usernames may be between one and eight
characters long.

Within a given UNIX machine, usernames are unique. No two users
can have the same one

A single person can have more than one UNIX account on the same
computer.

UNIX passwords are between one and eight characters long.

More than one user can theoretically have the same password.
Invitation to Computer Science, C++ Version, Third Edition
42
UNIX – User IDs & Passwords Cont’d.


UNIX uses the /etc/passwd file to keep track of every user on the
system.
It contains the username, real name, identification information, and
basic account information for each user
root:fi3sED95ibqR6:0:1:System Operator:/:/bin/ksh daemon:*:1:1::/tmp:
uucp:OORoMN9FyZfNE:4:4::/var/spool/uucppublic:/usr/lib/uucp/uucico
rachel:eH5/.mj7NB3dx:181:100:Rachel Cohen:/u/rachel:/bin/ksh
arlin:f8fk3j1OIf34.:182:100:Arlin Steinberg:/u/arlin:/bin/csh
rachel
H5/.mj7NB3dx
181
100
Rachel Cohen
/u/rachel
/bin/ksh
The
The
The
The
The
The
The
usernamee
user's "encrypted password“
user's user identification number (UID
user's group identification number (GID
user's full name
user's home directory
user's shell
Invitation to Computer Science, C++ Version, Third Edition
43
UNIX – Encrypted Password System

When UNIX requests your password, it needs some way of
determining that the password you type is the correct one.

In the /etc/passwd file UNIX stores a value that is generated by using
the password to encrypt a block of zero bits with a one-way function
called crypt( ) .

When you try to log in, the program / bin/login takes the password
that you typed, uses it to transform another block of zeros

It then compares the newly transformed block with the block stored
in the /etc/passwd file.

If the two encrypted results match, the system lets you in.
Invitation to Computer Science, C++ Version, Third Edition
44
UNIX – File Permission System


The UNIX filesystem controls the way that information in files and
directories is stored on disk and other forms of secondary storage.
It controls which users can access what items and how.
% ls -lF total 161
-rw-r--r-- 1 sian user 505 Feb 9 13:19 instructions
-rw-r--r-- 1 sian user 3159 Feb 9 13:14 invoice
-rw-r--r-- 1 sian user 6318 Feb 9 13:14 letter
-rw------- 1 sian user 15897 Feb 9 13:20 more-stuff
-rw-r----- 1 sian biochem 4320 Feb 9 13:20 notes
-rwxr-xr-x 1 sian user 122880 Feb 9 13:26 stats* %

Here are two examples of file permissions
-rw------drwxr-xr-x
Invitation to Computer Science, C++ Version, Third Edition
45
UNIX – File Permission System

Starting with the second character, nine characters taken in groups
of three indicate who on your computer can do what with the file.

There are three kinds of permissions:




r
w
x
Permission to read
Permission to write
Permission to execute
Similarly, there are three classes of permissions:



owner
group
other
The file's owner
Users who are in the file's group
Everybody else on the system (except the superuser)
Invitation to Computer Science, C++ Version, Third Edition
46
UNIX – File Permission System

Consider this listing
-rw-r--r-- 1 sian user 505 Feb 9 13:19 instructions
Field Contents
rw-r--r-1
sian
user
505
Feb 9 13:19
instructions



rwr-r--
Meaning
The file's type
The file's permissions
The number of "hard" links to the file
The name of the file's owner
The name of the file's group
The file's size, in bytes
The file's modification time
The file's name
user permissions
group permissions
other permissions
Invitation to Computer Science, C++ Version, Third Edition
47
Efficient Allocation Of Resources

The operating system ensures that

Multiple tasks of the computer may be underway
at one time

Processor is constantly busy

Keeps a “queue” of programs that are ready to run

Whenever processor is idle, picks a job from the
queue and assigns it to the processor
Invitation to Computer Science, C++ Version, Third Edition
48
Efficient Allocation Of Resources
•The typical I/O operation might require several milliseconds to
execute so the OS tries to keep the processor busy performing other
useful tasks.
•It maintains three classes of programs:
•The Running class contains the program currently executing in
the processor.
•The Ready class contains any other programs that are loaded
into memory and ready to run.
•The Waiting class contains those programs that cannot run yet
because they are waiting for some I/O operation to complete.
Invitation to Computer Science, C++ Version, Third Edition
49
State Diagram for Process Management
• If the program in the
Running class initiates an
I/O operation, the OS
moves it to the Waiting
class and moves some
other program from the
Ready class to the
Running class.
• A program in the Waiting
class is moved to the
Ready class whenever its
I/O operation completes.
Invitation to Computer Science, C++ Version, Third Edition
50
Process Management Queues
A
B
E
C
D
Running
B
Ready
C
D
E
A
→
Waiting
Process A issues an i/o request and is moved to the end of the Waiting queue.
Process B is moved to Running status
Processes C & D move up in the Ready queue
Invitation to Computer Science, C++ Version, Third Edition
51
The Safe Use Of Resources


Deadlock

Two processes are each holding a resource the
other needs

Neither process will ever progress
The operating system must handle deadlocks

Deadlock prevention

Deadlock recovery
Invitation to Computer Science, C++ Version, Third Edition
52
Traffic Deadlock
Invitation to Computer Science, C++ Version, Third Edition
53
Resource Deadlock Example

Imagine a system with one laser printer, one data file D,
and two programs, A and B.

Each program makes the following requests to the OS

Program A
Get data file D
Get the laser printer
Print the file

If the OS grants each program’s initial request we have a
deadlock.
Invitation to Computer Science, C++ Version, Third Edition
Program B
Get the laser printer
Get data file D
Print the file
54
Communication Deadlock Example

Imagine a telecommunication system. Program A sends messages
to program B, which acknowledges receipt.

A cannot send another message to B, until B acknowledges correct
receipt of the first message.

Program A
Message 
Message 
Message 
Program B
 Acknowledge
 Acknowledge

Say B sends and Ack, but it gets lost.

Deadlock. A and B are both stopped waiting on the other.
Invitation to Computer Science, C++ Version, Third Edition
55
Solutions to Resource Deadlock

Deadlock Prevention – OS uses resource allocation
algorithms that prevent deadlock from occurring.

If a program cannot get all the resources it needs, it must
give up all the resources it currently owns and issue a
completely new request

Program A
1.Get data file D
3.Get the laser printer
5.Print the file

At point 3, program A cannot get the printer and must relinquish the
data file. Program B gets the file and prints.
Invitation to Computer Science, C++ Version, Third Edition
Program B
2.Get the laser printer
4.Get data file D
6.Print the file
56
Solutions to Communication Deadlock

Program A
Message01 
Program B
 Acknowledge01
Message02 
Message03 

 Acknowledge02

 Acknowledge03
New protocol



Break message into parts and number the parts consecutively
A sends Message-N . If Ack-N is not received in a set time interval, A
resends Message-N
B receives Message-N. It sends Ack-N and discards any previous copies
of Message-N
Invitation to Computer Science, C++ Version, Third Edition
57
Historical Overview of Operating
Systems Development

First generation of system software (roughly
1945–1955)

No operating systems

Assemblers and loaders were almost the only
system software provided
Invitation to Computer Science, C++ Version, Third Edition
58
Historical Overview of Operating
Systems Development (continued)

Second generation of system software (1955–
1965)

Batch operating systems

Ran collections of input programs one after the
other

Included a command language
Invitation to Computer Science, C++ Version, Third Edition
59
Figure 6.18
Operation of a Batch Computer System
Invitation to Computer Science, C++ Version, Third Edition
60
Historical Overview of Operating
Systems Development (continued)

Third-generation operating systems (1965–
1985)

Multiprogrammed operating systems

Permitted multiple user programs to run at once
Invitation to Computer Science, C++ Version, Third Edition
61
Historical Overview of Operating
Systems Development (continued)

Fourth-generation operating systems (1985–
present)

Network operating systems

Virtual environment treats resources physically
residing on the computer in the same way as
resources available through the computer’s
network
Invitation to Computer Science, C++ Version, Third Edition
62
Figure 6.22
The Virtual Environment Created by a Network Operating System
Invitation to Computer Science, C++ Version, Third Edition
63
The Future

Operating systems will continue to evolve

Possible characteristics of fifth-generation
systems

Multimedia user interfaces

Parallel processing systems

Completely distributed computing environments
Invitation to Computer Science, C++ Version, Third Edition
64
Figure 6.23
Structure of a Distributed System
Invitation to Computer Science, C++ Version, Third Edition
65
Figure 6.24
Some of the Major Advances in Operating Systems Development
Invitation to Computer Science, C++ Version, Third Edition
66
Summary

System software acts as an intermediary
between the users and the hardware

Assembly language creates a more productive,
user-oriented environment than machine
language

An assembler translates an assembly language
program into a machine language program
Invitation to Computer Science, C++ Version, Third Edition
67
Summary

Responsibilities of the operating system

User interface management

Program scheduling and activation

Control of access to system and files

Efficient resource allocation

Deadlock detection and error detection
Invitation to Computer Science, C++ Version, Third Edition
68