Skip to content
Official PYQ · 2025

GATE CS 2025 Set 1 Q19 — CPU Scheduling

Explain with AI

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;
}
View worked solution

Answer: 21:21

To find the number of times the process enters the ready queue during its lifetime (excluding the initial entry), we analyze the I/O operations in the program segment:

  1. Input Operation (scanf): The statement scanf("%d", &x); is executed once. This triggers an I/O request, moving the process to the I/O queue. When this I/O completes, the process returns from I/O and enters the ready queue.
    Ready queue entries from scanf = 1
  2. Output Operations (printf): The for loop runs exactly 20 times (for i=0,1,…,19i = 0, 1, \dots, 19). In each iteration, the statement printf("%d\n", x); is executed. Each printf is an I/O operation that moves the process to the I/O queue. Upon completion of each print operation, the process enters the ready queue.
    Ready queue entries from printf = 20

Summing these up, the total number of times the process enters the ready queue after completing an I/O operation is:

Total Entries=1 (from scanf)+20 (from printf)=21\text{Total Entries} = 1 \text{ (from scanf)} + 20 \text{ (from printf)} = 21

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore CPU Scheduling questions