Karvell Li Notes from Friday, 4/11/02 ********************************************************************** The point of this lecture is The CPU acts as the government to divide resources enabling multiple programs to run on the same machine at the same time. There is one OS (government) and many address spaces for user programs (individuals) at any given time, but why is it this way? So programs can be tricked into thinking it is running in the same address space every time. Historic reasons Prior to 1960 A computer consists of 1. CPU Prices Steady 2. Memory Prices Steady 3. I/O devices Prices Steady TTY (teletypewriter) Card Readers Glass Console (for info on TTY, see http://whatis.techtarget.com/definition/0,,sid9_gci213663,00.html) Serial Access to the CPU is as efficient as parallel access. Since prices are steady and demand is low, there was no motivation to timeshare the CPU. Crash model Only one program runs at a time, if it crashes, it will only mess up itself and won't affect other programs/users. There was no real need for an OS. Year 1962 A computer consists of 1. CPU Prices Steady or going up. Every new model is different so is expensive. 2. Memory Prices Going down. Memory is the same. Lots of regularity = cheap. 3. I/O devices Prices Going down. TTY Card Readers Glass Console I/O's are slow so it takes time to input programs. Having lots of them would keep the CPU busy. In order to run all these programs, more memory is needed (there is a synergy between I/O and memory). Since memory and I/O are relatively cheap, we can afford to have lots of them and improve the computer's performance by using parallel access (running multiple programs at the same time). Since multiple programs are running at the same time, the crash model of pre 1960s no longer works. New crash Model isolate one program from another isolate application from OS OS must be the government. Since there is a limited amount of resources, the OS must decide how to share it among the different programs. Today Things are changing, I/O becoming more expensive relative to the CPU whose prices are constantly driven down by advances in technology and competition in the market. ____________________________________________________________________ Things that enable multi program/time share of CPU clock interrupt code in trap handler mechanism to context switch between address spaces The essence of timesharing - slowly changing the states of many processes - more slowly than if only one process was running. Scheduling - decides how fast a process runs (no CPU resource or full CPU resource, or more often, a point in between) A Process is Program in execution It consists of Address space code data empty space Registers needed to give instructions to CPU communicate w/ the CPU Address space and Registers are used to maintain the STATE of the program A process also needs a MEANS to change the state ____________________________________________________________________ The OS has complete view of all address spaces and view the entire space as DATA. Code is code because they are interpreted as code – that is the ONLY difference between code and data. OS see Process as pile of data Process sees itself as code and data (writing a program is to decide what data to use) A sample program int p() { int x; x = foo(7); //push 7 on stack, transfer to foo //assignment after return from foo } int foo(int y) { return y + 2; //value of on stack (7), add 2, returns 7+2 } Data structures are used to maintain flow of execution and to represent the state of execution. OS only does state management between processes maintains queue to do this The queues Ready Idle/waiting (like waiting for I/O devices) Running (currently bound to processor) Running processes has three options - keep running, go to idle, or go to ready. >From OS's point of view, a process is just a process control block. A process control block (PCB) consist of Address space Registers Owner TTY Runtime Priority When OS switches process (context switch) 1. saves PCB of currently running process into PCB old 2. restore states from PCB of new process