Introduction What is an Operating System? 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 An Operating System is a Program It acts as an interface between the user and the hardware System/Application Barrier add x,y mov a,b jump label Operating System Software (Code and Data Structures) User Application Programs P M Computer Hardware (ors, Memory & Devices) A Primitive 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 1 CS Basic OS 2 Historical Perspective Historical Perspective (cont) 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 Problem: Job to Job Setup Time 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 CS Basic OS 3 CS Basic OS 4
Historical Perspective (cont) 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; } 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 eg Read one Card or Print One Line CS Basic OS 5 CS Basic OS 6 Historical Perspective (cont) Historical Perspective (cont) Off Line Operation 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 Goal Speed up Computation; How Add Tapes Card Reader Printer Satellite or IN OUT IN OUT Main Computer IN IN User Could do I/O System Insecure CS Basic OS 7 CS Basic OS 8
Historical Perspective (cont) Historical Perspective (cont) Spooling: Overlap the I/O of One Job With the Computation of Another Job Buffering: Overlap the I/O of a Job With the Job s Own Computation 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 Synchronous CPU SIO I/O Asynchronous CPU I/O SIO CS Basic OS 9 CS Basic OS 10 How to do Asynchronous I/O Buffering Example Direct Memory Access (DMA) I/O Commands CPU I/O Devices Memory Read one Command at a Time From the Terminal and it 1 Allocate 2 Buffers (B 1 and B 2 ) 2 Read First Line Into B 1 3 Read Next Line Into B 2 While ing B 1 4 When Done ing B 1 Wait Until B 2 is Full Channels I/O Commands 5 Read Next Line Into B 1 While ing B 2 6 When Done ing B 2 Wait Until B 1 is Full 7 Goto Step 3 CPU Channel Memory I/O Devices CS Basic OS 11 CS Basic OS 12
Problem: How Do We Know That the I/O is Done? Interrupts and Traps (Exceptions) 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 Interrupts Device I/O Completion Device Attention Request Hardware Failure Traps Arithmetic Overflow Memory Fault Illegal Instruction CS Basic OS 13 CS Basic OS 14 Interrupt (Trap) ing How to use Interrupts for Buffering 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) 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; } CS Basic OS 15 CS Basic OS 16
Multiprogramming Problems With 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 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 or by Never Blocking CS Basic OS 17 CS Basic OS 18 Protecting I/O Problem: How Do We Get Into System Mode in the First Place 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 Whenever an Interrupt or Trap Occurs Add a Special Trap For Program to Request Service From the Operating System (SVC) CS Basic OS 19 CS Basic OS 20
Protecting Memory Protecting the CPU (Timesharing and Interactive Computing) Bounds Registers Lower Bound Register Upper Bound Register System Program #1 Program #2 Program #3 Program #4 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 Must Be Executing in System Privilege Mode to Load Bounds Registers When in System Privilege Mode Ignore Bounds Registers CS Basic OS 21 CS Basic OS 22 Classes of Computers Summary Personal Computers Workstations Mainframes Multiprocessors Distributed Systems Real Time Systems 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 CS Basic OS 23 CS Basic OS 24
Operating System Components Management Management Memory Management Secondary Storage Management I/O System File Management Protection System Networking System Programs Create and Delete es Suspend and Resume es Allow es to Synchronize Interprocess Communication Deadlock Detection, Avoidance, & Correction CS Basic OS 25 CS Basic OS 26 Memory Management Secondary Storage and I/O Keep Multiple es in Memory Decide When to Load and Unload es Share Memory Between es Allocate and Deallocate Memory to a Retrieve and Store Data Abstract Device Details Schedule Disk Activity Allocate Disk Space Buffer Data Handle I/O Interrupts CS Basic OS 27 CS Basic OS 28
File Systems Protection Create and Delete Files Create and Delete Directories Read/Write Files Map Files Onto Disks Protect Users From Each Other Protect User From Himself Protect System From Users CS Basic OS 29 CS Basic OS 30 Networks System Programs Let Users on Different Systems Exchange Data Let Different Systems Exchange Data Distributed Systems 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 CS Basic OS 31 CS Basic OS 32
Types of Operating System Services System Calls User Interface Program Execution Input/Output Operations File System Manipulation Error Detection System Control Resource Allocation Accounting Protection 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 33 CS Basic OS 34 How System Calls Work System Design and Implementation 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 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 CS Basic OS 35 CS Basic OS 36
Operating System Structuring Techniques A Monitor Single Monitor Kernel Layered Systems Hierarchy Functional Hierarchy Virtual Machine Message-Passing Port Based Based Object-Based Object-Oriented es Waiting for a Condition x: y: z: protected data es Waiting to Enter Monitor CS Basic OS 37 CS Basic OS 38 A Kernel Layered System user program logical communication user program Break Kernel up into Successive Layers of Abstraction Kernel physical communication process management interprocess communication interrupt handling User Programs Interface Primitives Device Drivers and Schedulers Virtual Memory I/O CPU Scheduling Hardware file system interrupt handler device driver CS Basic OS 39 CS Basic OS 40
Message-Passing System Object-Based System user program Send user program Object Object Object Reply operation system service program operation system service Computer 1 Computer 2 Object system service user program Object system service Object system service OS CS Basic OS 41 CS Basic OS 42 Object-Oriented System Summary Start With Object-Based Model Implement Very Efficient Message Send Add Very Lightweight Objects Add Classes to Define Objects Add a Hierarchy of Classes Operating System Components: Management, Memory Management, File Management, etc User Interface Command Interpreter System Programs System Calls Design and Implementation Structuring Techniques CS Basic OS 43 CS Basic OS 44
This page intentionally left blank This page intentionally left blank CS Basic OS 45 CS Basic OS 46 This page intentionally left blank CS Basic OS 47