Context Switching in Operating System
About Context Switching in Operating System
On this page, we will learn the concepts of Context switching in Operating System. Context switching refers to the methodology of switching a task or process from one state to another using CPU and other resources. It helps to complete the execution of all the tasks. It explains the properties of a multitasking operating system in which multiple processes shared the same CPU to perform multiple tasks
Context Switch in OS
Context Switching is a cost and time saving measure performed by the CPU that is handing task 1 and has to stop executing this task to priority execute another task 2. To do this effectively, the system stores the initial task in its processed form so that when this task is resumed, it can be loaded and resumed from the same progress point as earlier.
This allows the computer to multitask and multiple processes can share the same CPU. This is also done to make sure that tasks do conflict one another, as they may be holding a same resource for execution like memory etc.
Steps Leading to Context Switching
In the above diagram the following happens –
- Process 1 running in the system
- Interrupt or system call appears
- Causes Process 1 to be saved into PCB 1 and switched out
- Process 2 is loaded from PCB 2 and executed
- Again interrupt or system call appears
- Process 2 is saved into PCB 2 and process 1 loaded from PCB 1
- Process 1 is executed
Triggers for Context Switching
- Interrupt Handling
- User and Kernel mode Switch – System may switch from user mode to the kernel mode, you can think of this as windows 10 running and system is switched to boot mode.
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment