Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972
§Completion of I/O triggers an interrupt §Hardware Trap: l Division by zero l Invalid memory access §Request for OS service l Trap/System call/Monitor call
Protection §Dual Mode Operation l User mode l Kernel mode §Mode bit (0/1) (MS-DOS did not have it) §System call (switches from user mode to kernel mode) §Privileged instructions should be executed in kernel mode only
Protection §Changing mode bit?
I/O Protection §User cannot issue I/O instructions directly §Changes to interrupt vector?
Memory Protection
§Changes to base and limit registers?
CPU Protection §E.g. Infinite loop executed by a process
CPU Protection §Timer handler?
Process :Program in execution Associated state (PC, SP, registers etc) Address space
Processes The Process Model §Multiprogramming of four programs §Conceptual model of 4 independent, sequential processes §Only one program active at any instant Logical program counter Execution order not reproducible
Process creation System initialization User request to create a new process
Process Termination Conditions which terminate processes 1.Normal exit (voluntary) 2.Error exit (voluntary) 3.Fatal error (involuntary) 4.Killed by another process (involuntary)
Process Hierarchies §Parent creates a child process, child processes can create its own process §Forms a hierarchy l UNIX calls this a "process group" §Windows has no concept of process hierarchy l all processes are created equal
§As a process executes, it changes state l new: The process is being created l running: Instructions are being executed l waiting: The process is waiting for some event to occur l ready: The process is waiting to be assigned to a processor l terminated: The process has finished execution
Process States ps in Unix Background processes
Process Control Block (PCB)
CPU Switch From Process to Process
Process Scheduling Queues §Job queue – set of all processes in the system §Ready queue – set of all processes residing in main memory, ready and waiting to execute §Device queues – set of processes waiting for an I/O device §Processes migrate among the various queues
Ready Queue And Various I/O Device Queues
Representation of Process Scheduling
§I/O parallelism: l overlap execution: make 1 CPU into many l (Real parallelism: > 1 CPU (multiprocessing)) §Completion time: l B’s completion time = 100s (A + B) So overlap Why processes? Speed emacs (Wait for input) gcc A B A B 20 s80 s Completion time for B? A? 10 s
Context Switch §When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process §Context-switch time is overhead; the system does no useful work while switching §Time dependent on hardware support
Passing of Parameters As A Table
Process Creation (Cont.) §Address space l Child duplicate of parent l Child has a program loaded into it §UNIX examples l fork system call creates new process l exec system call used after a fork to replace the process’ memory space with a new program