I. Operating System (OS) Overview A. What is an OS? ------------------------------------------ OPERATING SYSTEM Goal: The task of an operating system (OS) is to Other goals General approach: virtualization, i.e., abstraction of physical resources defines APIs for them = system calls ------------------------------------------ What kinds of I/O devices might you find on a computer? B. Some Early History ------------------------------------------ SOME HISTORY OF OPERATING SYSTEMS Early days: human operator ran jobs OS = libraries for I/O 1960s: protection via system calls imagine library that can read any part of a disk drive: Is any information safe then? System calls: hardware tracks privilege level users run in "user mode" OS runs in "kernel mode" call to system involves: a trap (user mode) -> trap handler starts kernel mode checks permissions return-from-trap instruction => back to user code (user mode) Multiprogramming (1970s, Unix): OS switches between tasks: - timesharing and interactivity - start of memory protection - issues of concurrency ------------------------------------------ How does user/kernel mode and the trap mechanism give protection? C. Organization of an OS 1. monolithic ------------------------------------------ WAYS TO ORGANIZE AN OS: MONOLITHIC No distinctions, boundaries between user and OS programs, all can directly use the BIOS drivers [Application Programs] | | | v v | [Systems progs] | | | | v | | [OS drivers] | | | | | v v v [BIOS device drivers] Advantages: Disadvantages: ------------------------------------------ What is a BIOS? 2. layered ------------------------------------------ LAYERED OS Each layer can only use 1 layer below it [Application Programs] | v [Layer N: OS calls] | ... | v [Layer 1: OS kernel] | v [Layer 0: hardware] Advantages: Disadvantages ------------------------------------------ 3. micro-kernel ------------------------------------------ MICRO-KERNEL OS Layers, but with kernel as small as possible. Non-essential components become (user-space) apps [Application Programs] | v [Layer L: OS calls] | ... | v [Layer 1: micro-kernel] | v [Layer 0: hardware] Advantages: Disadvantages: ------------------------------------------ 4. modular ------------------------------------------ MODULAR OS Kernel has set of basic services, other services added as dynamic modules. Each module has defined API, but any module can call any other module ------------------------------------------ II. Processes A. What is a process? ------------------------------------------ PROCESS def: a *process* in an OS is A process is also called a *task* OS Goal: Characteristics: ------------------------------------------ ------------------------------------------ PROGRAM VS. PROCESS Is a program a process and vice versa? How does a program become a process? ------------------------------------------ 1. Process Control Block (PCB) ------------------------------------------ PROCESS CONTROL BLOCK (PCB) def: a *process control block (PCB)* is Typical information in a PCB: ------------------------------------------ Why put the BP, SP, and PC into the PCB? 2. Process Address Space ------------------------------------------ PROCESS ADDRESS SPACE def: a *process address space* is Layout (in Unix): |-------------------| | Stack | | | | | v | | | | | |-------------------| | | | ^ | | | | | Heap | |-------------------| | | | Data | | | |-------------------| | | | Text | | | |-------------------| ------------------------------------------ 3. Process States ------------------------------------------ PROCESS STATE def: a *process state* represents the Examples: Ready: Running: Waiting: Suspended: End: Abend: ------------------------------------------ 4. Events ------------------------------------------ AN OS AS AN EVENT-DRIVEN PROGRAM [Suspended] ^ / dispatch |stop resume create /-----\ | v *---> [Ready] |--> [Running] ^ ^ / | || EOP | \--------- / | \->[End] I/O| timer /SIO | interrupt / |trap \--[Waiting]-/ v [Abend] ------------------------------------------ Why would the OS need to stop a running program?