Day 08 Processes
Can you think of the states in a 5-state model?
i.e. 5-state model
Suspended Processes Processor is faster than I/O so all processes in main memory could be waiting for I/O Swap these processes to disk to free up main memory Blocked process becomes a suspended process when swapped to disk
One Suspend State
7-state model - two suspend states
Reasons for Process Suspension
Modes of execution User mode – restricted access to memory and restricted access to certain instructions. Kernel mode or system mode – when the OS is in control. Access to privileged instructions.
Mode switch How to set and reset the mode? Hardware level support required. Mode bit (part of the Process Status Word) When an interrupt is detected, control is transferred to the OS (i.e. privileged mode is required) Change the mode bit When the interrupt service routine is done, control is transferred back to a user program (i.e. non-privileged mode) Change the mode bit again.
Process switching When can a process switch occur? Examples: Anytime the OS takes over from the user process. Examples: Interrupt – external to the currently running process – clock INT, I/O interrupt, memory fault (page or segment) Trap – error exception internal to the program may have a recovery procedure or simply notify and quit Supervisor call – explicit request from the program (system call).
Process Switching – Supervisor call
Process switching – Timer interrupt
Context/mode switch Context/mode switch - When the processor switches between a user process and an OS process or vice versa. Involves the following steps: Set the PC value to the address of the ISR. Change to kernel model so that the ISR may access privileged instructions. Save the context of the process i.e. the general purpose registers, stack information, and PC value.
Context switch or Process switch? When a context switch occurs, the PCB of the process that was running is still marked Running and is not placed in the Blocked or Ready queue. However, depending on what caused the context switch, a process switch could follow.
Process switch When the processor switches between two user processes. Save the context of the current process Update the PCB to the new state. Move the PCB to new queue Select another process for execution Update the PCB of the next process Move the PCB of the next process to Running Update memory-mgmt data structures Restore the context of the processor to that of the new process. Lots of work! Design goal: Minimize the number of process switches.