Process /Task 1 Process Management Creation & termination of processes (user + System) Interleaving the execution of processes Scheduling of processes Synchronization mechanism between processes Communication Deadlock handling 2 1
Creation of Processes New Batch Job: Interactive Log on: To provide a Service: Branching & Spawning: Department of Electronic Systems DE5 3 Termination of Processes Normal Completion: Time Limit: Memory Not Available: Address Space Violation: Protection Error: Arithmetic Overflow: I/O Failure Invalid Instruction Privileged Instruction: Data Misuse: Operator/OS Intervention: ParentRequestTermination: Parent Termination: Department of Electronic Systems DE5 4 2
Basic Two State Model Enter Not Executing Executing Exit 5 Three State Model Enter Ready Dispatch Time Out Executing Exit Waiting/Blocked Quanta: Windows: 6 ticks 12 ticks LINUX 10 ticks 200 ticks Tick in Windows = 10 to 15 ms Tick in LINUX = 1 ms 6 3
Five State Model New Dispatch Ready Executing Time Out Event Wait Event Occur Blocked?? Exit 7 Suspended Processes New Ready Dispatch Time Out Executing Exit Suspended Suspended Blocked 8 4
Modified Suspended Model New Ready Suspend Activate Suspended Ready Dispatch Time Out Executing Exit Blocked Suspend Activate Suspended Blocked 9 UNIX PROCESS STATES 10 5
Process Description Solid Line: Process has Resource Dashed Line: Process needed that Resource P1 P2 Pn PROCESSOR I/O I/O I/O MAIN MEMORY WHICH PROCESS IS EXECUTING? 11 Operating System Control Structure Allocation of main memory to the processes. Allocation of secondary memory to the processes. Any protection attributes concerning segments of main or virtual memory, such as which process can access certain memory area of the process. Any information required for the management of virtual memory. 12 6
Operating System Control Structure MEMORY DEVICES FILES PROCESSES MEMORY TABLES I/O TABLES Process Image PROCESS 1 FILE TABLES Primary Process Table PROCESS 1 PROCESS 2 PROCESS 3 PROCESS N PROCESS N 13 Structure Two fundamental Requirements for the management of processes: Process Location Attributes Department of Electronic Systems DE5 14 7
Process Image Process Identification Processor State Process Identification Processor State Process Control Box Process Identification Processor State User Stack User Stack User Stack Private User Address Space (Program, Data) Private User Address Space (Program, Data) Private User Address Space (Program, Data) Shared Address Space Shared Address Space Shared Address Space Process 1 Process 2 Process n 15 Identification & Process Identification Identifiers: includes. The numeric identifiers that can be stored in the PCB Identifier of the process Identifier of the process that has created this process (parent) User identifier 16 8
Identification & Processor State t User Visible Registers: Control & Status Registers: 17 Pentium II EFLAGS Registers 18 9
Scheduling & State : Process State: The process could be in any of the states like ready, blocked etc. Priority: One or more bits may be used to indicate the priority of the scheduling. In some machines there could be information like default, current & highest allowable. Scheduling Related : This really depend on the technique/scheme used, for example how much time one process is given. Event: Identification of the event for which the process is waiting. 19 Data Structuring: A process may be linked with some other process through a structure like queue, linked list etc., or it may be a parent-child relationship, so PCB must have pointers to indicate such relationships. Inter Process Communication: Various flags, messages may be associated with communication between two independent processes, so some information may be required to be stored in the PCB. Process Privileges: Different processes may be granted some privileges in terms of memory they may access, types of instructions or may be in terms of other resources utilization. Memory Management: This part consists of pointers to pages or segments assigned in the virtual memory for a particular process. Resource Ownership & Utilization: A track/history of the resources utilized by a process may be kept in the PCB for scheduling purpose, resources like open/close etc., may also be indicated in the information. Department of Electronic Systems DE5 20 10
The Role of PCB Running Ready Blocked 21 Interrupt Trap Memory Fault Supervisor Call Process Switching & Mode Switching 22 11
Steps in Process Switching: Saving the context of the processor, including PC & other registers. Update PCB of the process which is in the running state, that is it may go into ready, blocked or suspended state, other fields like reason of leaving the current state & accounting information may also be updated. Moving the PCB of this process to an appropriate queue, ready, blocked or suspended. Select another process for execution. Now updating the PCB of this process that is from ready to running. Update memory management data structure (table). Restoring the context of the processor to those setting, at which the current process was last switched out of therunning state. t Department of Electronic Systems DE5 23 Execution of Operating System P1 P2 Pn KERNEL Non-Process Kernel 24 12
Execution of Operating System P1 O/S Functions P2 O/S Functions Process Switching Function Pn O/S Functions O/S within a User Process 25 Execution of Operating System U1 U2 Un OS 1 OS 2 OS n Process Switching Function Process Based O/S 26 13