Skip to content
GATEiit

GATE CSE 2025 Session 1 Q29: Times a process re-enters the ready queue due to I/O

Question

Suppose in a multiprogramming environment, the following C program segment is executed. A process goes into I/O queue whenever an I/O related operation is performed. Assume that there will always be a context switch whenever a process requests for an I/O, and also whenever the process returns from an I/O. The number of times the process will enter the ready queue during its lifetime (not counting the time the process enters the ready queue when it is run initially) is _______. (Answer in integer)

int main()
{
    int x=0,i=0;
    scanf("%d",&x);
    for(i=0; i<20; i++)
    {
        x = x+20;
        printf("%d\n",x);
    }
    return 0;
}

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 21 (official GATE 2025 final answer key)

Concept used: Process state transitions: after each I/O completes, the process goes from waiting back to ready.

First step: Count the I/O operations: one scanf plus one printf per loop iteration.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2025 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key