- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can kernels context-switch between processes?
Whenever the transaction between user and kernel mode is required, a context switch is not necessary; simply a mode transition is not a context switch. Because, depending on the operating system, a context switch may also take place at this time.
Let us see the major steps of Context Switching
The values of the CPU registers are generally saved in the process table of the process which was running before the clock interrupt occurred.
To run next the registers are loaded from the process and picked by the CPU scheduler.
Consider a multi-programmed single processor system, the context switches occur frequently so that all processes appear to run concurrently. If a process has more than one thread, the Operating System uses the context switching technique to schedule the threads so they appear to execute in parallel.
It is the case if threads are implemented at the kernel level. Threads can also be implemented at the user level in run-time libraries. Because, no thread scheduling is provided by the Operating System, and it is the responsibility of programmer to provide the CPU frequently enough in each thread so all threads in the process can make progress
Context switches among processes are very expensive. Before a process is switched its process control block (PCB) has to be saved by the operating system.
The PCB consists of the following information −
The process state.
The program counter, PC.
The values of the different registers.
The CPU scheduling information for the process.
Memory management information regarding the process.
Possible accounting information for this process.
I/O status information of the process.
Whenever the PCB of the currently executing process is saved by the operating system, then that loads the PCB of the next process that has to be run on the CPU. This is a heavy task and it takes more time.
Let us see the diagram below of how the context switching takes place between the processes −
- Related Articles
- Actions taken by a kernel to context-switch between processes
- What's the difference between a context switch, a process switch and a thread switch in Linux?
- Actions taken by a kernel to context-switch between kernel-level threads.
- Difference between One-Way Switch and Two-Way Switch
- Differentiate between process switch and mode switch in OS
- How can I style an Android Switch widget?
- How to switch between different activities in android?
- How to switch between two frames in Tkinter?
- Difference between Router and Switch
- Difference between Hub and Switch
- Difference between Gateway and Switch
- How can a binary semaphore implement mutual exclusion among n processes?
- What is Kernel and different types of Kernels?
- Difference Between if-else and switch
- How to switch between hide and view password in Android
