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 switching in operating system

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.

Context Switching in OS

Steps Leading to Context Switching

In the above diagram the following happens –

  1. Process 1 running in the system
  2. Interrupt or system call appears
  3. Causes Process 1 to be saved into PCB 1 and switched out
  4. Process 2 is loaded from PCB 2 and executed
  5. Again interrupt or system call appears
  6. Process 2 is saved into PCB 2 and process 1 loaded from PCB 1
  7. Process 1 is executed
 
 

Triggers for Context Switching

  1. Multitasking
  2. Interrupt Handling
  3. 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.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

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

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription