Page 81 - DCAP103_Principle of operating system
P. 81
Principles of Operating Systems
Notes 3.3.10 Context Switching Perform
Typically there are several tasks to perform in a computer system. So if one task requires some
I/O operation, you want to initiate the I/O operation and go on to the next task. You will come
back to it later.
This act of switching from one process to another is called a “Context Switch”.
When you return back to a process, you should resume where you left off. For all practical
purposes, this process should never know there was a switch, and it should look like this was
the only process in the system.
To implement this, on a context switch, you have to
• save the context of the current process
• select the next process to run
• restore the context of this new process.
What is the context of a process?
• Program Counter
• Stack Pointer
• Registers
• Code + Data + Stack (also called Address Space)
• Other state information maintained by the OS for the process (open files, scheduling info,
I/O devices being used, etc.)
All this information is usually stored in a structure called Process Control Block (PCB). All the
above has to be saved and restored.
3.3.10.1 What does a context_switch( ) routine look like?
context_switch()
{
Push registers onto stack
Save ptrs to code and data.
Save stack pointer
Pick next process to execute
Restore stack ptr of that process /* You have now switched the stack */
Restore ptrs to code and data.
Pop registers
Return
}
3.3.11 Super OS Context Switching in Power Managed Environment
Super OS context switching consists of a process which suspends the currently operating OS,
when and as determined by user and transfer of the systems control to another OS, which
may be booting from shut down state (Start) or a previously suspended state (Resume).
74 LOVELY PROFESSIONAL UNIVERSITY