Introduction
1. What is an Operating System?
2. Why is an Operating System Needed?
3. How Did They Develop?
• Historical Approach
• Affect of Architecture
4. Efficient Utilization of CPU and I/O 5. Types of Operating Systems
CS — Basic OS –1–
What is an Operating System?
• An Operating System is a Program
• It acts as an interface between the user and the hardware.
P
M add x,y
mov a,b jump label
.. .
.. .
User Application Programs System/Application
Barrier
Operating System Software (Code and Data Structures)
A Primitive
Computer Hardware (Processors, Memory & Devices)
• Its purpose is to:
– Make the computer convenient to use – Simulate features the hardware does not have – Improve efficiency of the computer
CS — Basic OS –2–
Historical Perspective
Bare Machine – Early 1950’s
• Structure
– Single User System
– Programmer/User as the Operator – Tape/Card Based
• Early Software – Loaders – Assemblers
– Libraries of Common Subroutines (birth of the first operating systems)
– Linkers – Compilers – Run-time System
• Secure
• Inefficient use of Expensive Resources
Historical Perspective (cont.)
Simple Batch Systems (single user at a time)
• Reduce Set Up Time by Batching Jobs
• Add a Card Reader
• Hire an Operator (User is not the Operator)
• Automatic Job Sequencing
• Problem: How to distinguish:
1. Job from Job 2. Data from Program
Historical Perspective (cont.)
• Solution: Control Cards
– Special Cards to Indicate What to Do: $JOB,
$FTN, $RUN, $DATA, $EOJ – Special Characters for Some Control
$ in Column 1 // in Column 1 and 2
– Control Card Interpreter (first Resident OS) forever {
read a card;
execute it;
}
CS — Basic OS –5–
Historical Perspective (cont.)
• Another Problem:
How to Keep User From Reading Control Cards?
– One Routine to Read Input
∗ In Library
∗ Everyone Uses it
∗ Never Reads Past a Control Card
∗ Device Driver
– Eventually, One For Every Device Which Knows Device Characteristics and Properties
– Virtual Device
e.g. Read one Card or Print One Line
CS — Basic OS –6–
Historical Perspective (cont.)
• Even More Problems:
1. System is Not Secure
– User Could do Own I/O and Avoid Device Driver
– Memory for Device Driver not Protected 2. Poor Performance
– I/O and CPU Cannot Overlap Work – I/O Devices Cannot Either
Historical Perspective (cont.)
Off Line Operation
Goal – Speed up Computation; How – Add Tapes
Main Computer
Satellite Processor
IN OUT Card
Reader
Printer
IN
IN
IN OUT
. . .
• User Could do I/O
• System Insecure
Historical Perspective (cont.)
Spooling: Overlap the I/O of One Job With the Computation of Another Job.
• While Executing One Job, Read the Next Job From the Card Reader Into a Storage Area on the Disk.
• While Executing One Job, Print the Output From Another Job.
CS — Basic OS –9–
Historical Perspective (cont.)
Buffering: Overlap the I/O of a Job With the Job’s Own Computation
• Synchronous
CPU I/O
SIO
• Asynchronous
CPU I/O
SIO
CS — Basic OS –10–
How to do Asynchronous I/O
• Direct Memory Access (DMA)
Memory CPU I/O Devices
I/O Commands
• Channels
Memory CPU
I/O Commands
Channel
I/O Devices
Buffering Example
Read one Command at a Time From the Terminal and Process it
1. Allocate 2 Buffers (B1and B2) 2. Read First Line Into B1
3. Read Next Line Into B2While Processing B1
4. When Done Processing B1Wait Until B2is Full 5. Read Next Line Into B1While Processing B2
6. When Done Processing B2Wait Until B1is Full 7. Goto Step 3
Problem: How Do We Know That the I/O is Done?
1. Polling
• Add a Flag Which is Set By The Device While it is Busy.
• Test the Flag and Loop When The Result of a I/O Request is Needed.
2. Interrupts
• Have the Device Tell the CPU When it is Done.
• The CPU Stops What it is Doing, Does Some Work for the Device, Then Continues Where it Left Off.
CS — Basic OS –13–
Interrupts and Traps (Exceptions)
• Interrupts
– Device I/O Completion – Device Attention Request – Hardware Failure
• Traps
– Arithmetic Overflow – Memory Fault – Illegal Instruction
CS — Basic OS –14–
Interrupt (Trap) Processing
1. Finish Executing The Current Instruction 2. Save Program Counter
3. Transfer to an Interrupt (Trap) Handler at a Predefined Location
4. Save the CPU State 5. Service the Interrupt (Trap) 6. Restore the CPU State
7. Resume at the Instruction Following the Instruction Interrupted
There is Usually an Unique Interrupt (Trap) Handler for Each Possible Kind of Interrupt (Trap)
How to use Interrupts for Buffering
program() {
. . .
busy = true;
send request to read buffer 2;
process buffer 1;
while( busy ) skip;
busy = true;
send request to read buffer 1;
process buffer 2;
while( busy ) skip;
. . . }
io_device() {
receive request;
process request;
send interrupt;
}
interrupt_handler() {
busy = false;
}
Multiprogramming
• Allow Multiple Programs to Reside in the Memory of the Computer at the Same Time
• When a Program Blocks, Instead of Waiting for Interrupt, Execute Another Program
• When that Program Blocks, Execute Yet Another Program.
• Etc...
CS — Basic OS –17–
Problems With Multiprogramming
1. Protect I/O Devices
• One Program May Corrupt Another Program by Directly Accessing That Programs Data on the I/O Devices.
2. Protect Memory
• One Program May Corrupt Another Program by Directly Accessing That Programs Memory.
3. Protect CPU
• One Program May Monopolize the Processor by Never Blocking
CS — Basic OS –18–
Protecting I/O
• Disallow Users to Access I/O Devices
• Introduce Privilege Operation Modes – Monitor/User
– Supervisor/User – Master/Slave – Kernel/User – ...
– System/Application
• Only all I/O While Executing in System Privilege Mode
Problem: How Do We Get Into System Mode in the First Place
• Whenever an Interrupt or Trap Occurs
• Add a Special Trap For Program to Request Service From the Operating System (SVC)
Protecting Memory
• Bounds Registers
System
Program #1
Program #2
Program #3
Program #4 Lower Bound
Register
Upper Bound Register
• Must Be Executing in System Privilege Mode to Load Bounds Registers
• When in System Privilege Mode Ignore Bounds Registers
CS — Basic OS –21–
Protecting the CPU
(Timesharing and Interactive Computing)
• Use Multiprogramming But Add a Timer to Force a Program to Block After a Certain Quantum of Time.
• Move Some (Idle) Programs Out of Memory to Mass Storage to Allow More Programs to Run.
• Replace the Control Card Interpreter With a Command Language.
CS — Basic OS –22–
Classes of Computers
• Personal Computers
• Workstations
• Mainframes
• Multiprocessors
• Distributed Systems
• Real Time Systems
Summary
• Operating Systems:
– Provide Convenient Environment for the Development and Execution of Programs – Schedule and Overlap Activities to Ensure Good
Performance From the Computer
• Evolved From Batch Systems to Multiprogrammed and Timeshared
Operating System Components
• Process Management
• Memory Management
• Secondary Storage Management
• I/O System
• File Management
• Protection System
• Networking
• System Programs
CS — Basic OS –25–
Process Management
• Create and Delete Processes
• Suspend and Resume Processes
• Allow Processes to Synchronize
• Interprocess Communication
• Deadlock Detection, Avoidance, & Correction
CS — Basic OS –26–
Memory Management
• Keep Multiple Processes in Memory
• Decide When to Load and Unload Processes
• Share Memory Between Processes
• Allocate and Deallocate Memory to a Process
Secondary Storage and I/O
• Retrieve and Store Data
• Abstract Device Details
• Schedule Disk Activity
• Allocate Disk Space
• Buffer Data
• Handle I/O Interrupts
File Systems
• Create and Delete Files
• Create and Delete Directories
• Read/Write Files
• Map Files Onto Disks
CS — Basic OS –29–
Protection
• Protect Users From Each Other
• Protect User From Himself
• Protect System From Users
CS — Basic OS –30–
Networks
• Let Users on Different Systems Exchange Data
• Let Different Systems Exchange Data
• Distributed Systems
System Programs
• Command Interpreter (sh, csh, ksh)
• Print File (lpr)
• Copy File (cp)
• Edit File (ed, vi, emacs)
• Display Directory (ls)
• Sort (sort)
• Compare Files (cmp, diff)
• Send Mail (mail)
• Read News (rn)
• Compile Programs (cc)
Command Interpreter Parses Commands and Executes Other System Programs
Types of Operating System Services
• User Interface – Program Execution – Input/Output Operations – File System Manipulation – Error Detection
• System Control – Resource Allocation – Accounting – Protection
CS — Basic OS –33–
System Calls
• Assembly Language Macros or Subroutines
• Need to Use an SVC Instruction
i = read(fd,80,buffer) --> push buffer push 80 push fd SVC read
pop i
• Unix Has About 32 System Calls
read(), write(), open(), close(), fork(), exec(), ioctl(), etc...
CS — Basic OS –34–
How System Calls Work
1. SVC Causes a Trap
2. System Privilege Mode Entered 3. Trap Handler Decodes Which SVC 4. Branch to System Function 5. Access Arguments From the Stack 6. Push Results on the Stack 7. Return to Trap Handler
8. Resume Application Privilege Mode 9. Return to Instruction Following SVC
System Design and Implementation
• Establish Design Goals – What are the Requirements
– What do Users Want (Know Your User) – Batch, Time-Shared, Single-User, Multi-User,
Distributed, Real-Time, General Purpose
• Use Good Software Engineering – Separate Policy from Mechanisms – Choose an Implementation Language
Operating System Structuring Techniques
• Single Monitor
• Kernel
• Layered Systems – Process Hierarchy – Functional Hierarchy – Virtual Machine
• Message-Passing – Port Based – Process Based
• Object-Based
• Object-Oriented
CS — Basic OS –37–
A Monitor
Processes Waiting to Enter Monitor
x:
y:
z:
protected data Processes Waiting
for a Condition
CS — Basic OS –38–
A Kernel
Process user program Process
user program
Process file system
Kernel
process management interprocess communication interrupt handling
Process interrupt handler
Process device driver logical communication
physical communication
Layered System
Break Kernel up into Successive Layers of Abstraction
User Programs Interface Primitives Device Drivers and Schedulers
Virtual Memory I/O CPU Scheduling
Hardware
Message-Passing System
Process user program
Process user program
Process user program
Process operation system service
Process operation system
service Computer 1
Computer 2 Send
Reply
CS — Basic OS –41–
Object-Based System
Object system service
Object system service
Object system service Object
Object
Object
program
OS
CS — Basic OS –42–
Object-Oriented System
• Start With Object-Based Model
• Implement Very Efficient Message Send
• Add Very Lightweight Objects
• Add Classes to Define Objects
• Add a Hierarchy of Classes
Summary
• Operating System Components: Process Management, Memory Management, File Management, etc...
• User Interface
– Command Interpreter – System Programs – System Calls
• Design and Implementation
• Structuring Techniques
This page intentionally left blank.
CS — Basic OS –45–
This page intentionally left blank.
CS — Basic OS –46–
This page intentionally left blank.