The Gateway to Computer Science Excellence
+51 votes

Let the time taken to switch from user mode to kernel mode of execution be $T1$ while time taken to switch between two user processes be $T2$. Which of the following is correct?

  1. $T1 > T2$
  2. $T1 = T2$
  3. $T1 < T2$
  4. Nothing can be said about the relation between $T1$ and $T2$
in Operating System by Veteran
recategorized by | 8.9k views

Notice  important point mentioned by @Sachin Mittal 1 -> Context switches can occur only in kernel mode.


This Link might be useful for understanding.

5 Answers

+97 votes
Best answer

Time taken to switch two processes is very large as compared to time taken to switch between kernel and user mode of execution because :

When you switch processes, you have to do a context switch, save the PCB of previous process (note that the PCB of a process in Linux has over $95$ entries), then save registers and then load the PCB of new process and load its registers etc. 

When you switch between kernel and user mode of execution, OS has to just change a single bit at hardware level which is very fast operation.

So, answer is: (C).

by Active
edited by

Moreover context switch involves a switch to the kernel mode too. 

But switching to kernel mode is not so fast- it is a system call. 

Arjun actually there is a mistake in GO pdf book for this question you swapped the options A and C. so please rectify it..
The question seems merged - in UGC they shuffled the options and someone merged that question with GATE. Anyway answer is clear rt?
Answer is wrong in GO book.

yes, Options are shuffled in GateOverflow book.


Switching from User mode to Kernel mode is not as straightforward as switching a single bit. In modern OS it is very expensive. Here this answer from SO has tried to put things in perspective.

Moreover, as @Arjun Sir said that context switch involves a switch from user mode to kernel mode, it just make things even more expensive.

but for threads it is reverse right ? Context switch time is longer for kernel level threads than for user level threads. −− This is True, as Kernel level threads are managed by OS and Kernel maintains lot of data structures. There are many overheads involved in Kernel level thread management, which are not present in User level thread management !

@Sanjay Sharma

I think it's not correct to put it that way. You can treat thread as a light weight process.

Time for CS between user level threads < Time for CS between kernel threads.

Time for CS between user level processes < Time for CS between kernel processes.

Reason is explained here:

(GATE PYQ reference:

Any process context switch has to happen in kernel mode only.

For user processes we will have to make use of a system call to call the kernel for context switch. So, this also also includes time to switch from user mode to kernel mode.

Here in this question,

T1 = time to switch from user mode to kernel mode

T2 = time for CS between user processes.

Clearly T1 < T2. Hence Option C is correct.

where did u get this fact ''PCB of a process in Linux has over 95 entries"??

Source code for a PCB structure in linux kernel:

(Check from line no 1023. It's very huge.)

On a linux terminal you can check any process information.

cat /proc/$$/status

$$ in the above command stands for the process_id of your current shell.

You can replace $$ with any process id.

Are register values also saved during a contect switch?
+66 votes
Context switches can occur only in kernel mode. So, to do context switch first switch from user mode to kernel mode and then do context switch (save the PCB of the previous process and load the PCB of new process)

Context switch = user - kernel switch + save/load PCB + kernel-user switch

C is answer.
by Boss
Mode switch doesnot involve a context switch whereas a context switch definitely needs a mode switch as context switch is done by the dispatcher which is a portion of OS code ... And as we know OS code can run only in kernel mode so we need a mode change while doing a context switch ...
pefect answer for the question
if context switch is only done in kernel mode then why context switching between user level threads is faster than context switching between kernel level threads?
Even when CPU switches from user mode to kernal mode then also we need to save the context of current executing process? correct me if i am wrong!!!!!!
And Mode Switch only has to flip Mode bit.

In Case of Context Switch in a Virtual Memory system with TLB,

TLB might need to be flushed, Memory Map of MMU needs to be changed, along with context save of preempted process and context restore of the process being resumed.
+8 votes

Context switching can be described in slightly more detail as the kernel (i.e., the core of the operating system) performing the following activities with regard to processes (including threads) on the CPU: (1) suspending the progression of one process and storing the CPU's state (i.e., the context) for that process somewhere in memory, (2) retrieving the context of the next process from memory and restoring it in the CPU's registers and (3) returning to the location indicated by the program counter (i.e., returning to the line of code at which the process was interrupted) in order to resume the process.

Context switches can occur only in kernel mode. Kernel mode is a privileged mode of the CPU in which only the kernel runs and which provides access to all memory locations and all other system resources. Other programs, including applications, initially operate in user mode, but they can run portions of the kernel code via system calls.

by Loyal
+1 vote
Ans is :T1<T2:Explanation already given by others
–1 vote
c As cs between processes involve loading processor state cpu registers into ram.
by Active

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,215 questions
60,009 answers
94,693 users