GATE / CS ARCHIVE

GATE CSE 2025 SET 1 / QUESTION 29

Counting returns from blocking I/O

Operating Systems · Processes, Threads & System Calls · Full GATE CSE 2025 Set 1 paper

GATE 2025 Set 1, Q29 1 mark · NAT
Report issue

Processes, Threads & System Calls

Question 29, GATE 2025: A process executes one scanf, then twenty loop iterations, each doing x=x+20 and one printf. Every I/O operation sends it to an I/O queue; context switches occur both on I/O requests and on returns. Excluding initial admission, how many times does it enter the ready queue during this program? Use the question’s stipulated blocking-I/O model.
Tap to enlarge
Answer & solution

Official answer: 21

Approach: Count the state transitions into Ready rather than all context switches.
The scanf causes one I/O request. The loop has exactly twenty iterations, so its printf causes twenty more requests. There are 21 I/O operations in all. Each request takes the process from Running to Blocked (the I/O queue); that transition does not enter the ready queue.
When each I/O operation completes, the blocked process becomes eligible to run again and enters Ready once. Thus 21 completions produce 21 ready-queue entries. The initially admitted Ready entry is explicitly excluded, giving the answer 21 rather than 22.
There can be two stipulated context-switch events around an I/O episode, but they must not both be counted as Ready entries. The intended model assumes no additional time-slice or priority preemptions; such unspecified events could add entries. It also treats library I/O as blocking regardless of real-world stdio buffering.

Original paper, page 29 · Answer key