The GATE Grind

GATE 2025 CS (CS1) – Question 29

Operating System · CPU and I/O Scheduling · 1 mark · Numerical answer

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;
}

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 21

Explanation

The process starts in the ready queue (that first entry is not counted). Every I/O request moves it to the I/O queue, and when the I/O completes it **re-enters the ready queue**. So the answer equals the number of I/O operations.

Number of times the process enters the ready queue (after the first time) $=1+20=\mathbf{21}$.

More CPU and I/O Scheduling questions

All CPU and I/O Scheduling questions →