in Operating System edited by
2,613 views
1 vote
1 vote

​​​​Consider a process $\text{P}$ running on a $\text{CPU}$. Which one or more of the following events will always trigger a context switch by the $\text{OS}$ that results in process $\mathrm{P}$ moving to a non-running state (e.g., ready, blocked)?

  1. $\text{P}$ makes a blocking system call to read a block of data from the disk
  2. $\text{P}$ tries to access a page that is in the swap space, triggering a page fault
  3. An interrupt is raised by the disk to deliver data requested by some other process
  4. A timer interrupt is raised by the hardware
in Operating System edited by
by
2.6k views

1 comment

Isn't the answer to the question implementation-specific? It makes no sense to say one option is right and the other is wrong.
1
1

1 Answer

1 vote
1 vote

A: True
If a Process itself makes a block() call then it will be blocked until I/O.

B: True.

If a page is not in the physical memory, then the OS invokes the Page Fault Handler, and the process remains blocked until the page is read (i.e., disk I/O is complete).

By the way, there are two types of page faults: Minor and Major. A Minor fault occurs when a page is already in physical memory but was brought earlier using some other process, and the current process might not be aware of it. This typically happens when pages are shared. A Major Page Fault, on the other hand, occurs when we need to access the disk to retrieve the page into physical memory.
You can read more about both types of page faults here: https://en.wikipedia.org/wiki/Page_fault

Since this question ask to get a page from the disk, it is considered a Major Page Fault. Therefore, the current process will be blocked until this I/O operation is completed.

Source: https://stackoverflow.com/q/13441732

C: False
That kind of request will be served by DMA and the CPU doesn't need to get involved hence the current program will keep on using the CPU.

D: False

Timer interrupts will be ignored in many cases and will not lead to a context switch.

Case 1: Consider non-preemptive scheduling like FCFS. In that case, either we disable the timer interrupt or ignore it. (See: (Q8) https://www.cse.iitb.ac.in/~mythili/os/ps/proc/ps-proc.pdf )

Case 2: Consider some scheduling algorithm or define something like "RR with Priority". Here, suppose we want to run process P1 for a quantum of 50 ms (high-priority process) and P2 for a quantum of 10 ms (low-priority process). So, what will be the time for the timer interrupt? It should be gcd(10,50) = 10. Now, whenever P1 is running and a timer interrupt occurs, we will ignore it four times and perform a context switch on the fifth occurrence, since we are ignoring it four times. Therefore, it is clear that it is not necessary to perform a context switch upon every timer interrupt.

edited by

4 Comments

Check this @Sachin Mittal 1 sir , they have mentioned common for cse too. 

0
0

@Shreyas16

Yes, it's mentioned as a common syllabus, but I'm guessing they won't ask about it for CSE.

Even if it does come up in the syllabus, most CSE students probably won't try those questions, so it won't affect much.

What I'm saying is, to focus on what you already know. Once you've gone through all the GATE PYQs for PGEE subjects and practiced plenty of aptitude questions, then you can think about looking into these other things.

0
0
Ok. Thank you sir.
0
0
Answer:

Related questions