in Operating System recategorized by
20,213 views
64 votes
64 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 recategorized by
20.2k views

2 Comments

edited by

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

16
16

http://www.linfo.org/context_switch.html

This Link might be useful for understanding.

2
2

6 Answers

130 votes
130 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).

edited by

4 Comments

yes register values are also saved in physical memory.
0
0
No, I just saw video by Mythili mam , IIT B, she said there are two types of Context switches

process to process also there is a context switch involved.

also there is a context switch from user to process

Process P1 to process P2, kernal to kernal context switch is done.
0
0

Yes Arjun sir, you are correct, 

honestly saying, I didnt even read your comment before writing the above comment. 

 

0
0
96 votes
96 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.

4 Comments

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!!!!!!
0
0
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.
1
1
Kernel-level context switch involves changing a large set of processor registers, security level(privilege) and cache of processor,

User-level context switch involves a procedure call for small amount of bookkeeping within one kernel thread or process.
0
0
9 votes
9 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.

http://www.linfo.org/context_switch.html

1 vote
1 vote
Ans is :T1<T2:Explanation already given by others
Answer:

Related questions