Skip to main content

GATE CSE 2025Operating System › CPU SchedulingVerified

GATE CSE 2025 PYQ: Suppose in a multiprogramming environment, the following C program segment is executed. A process goes into…

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)

  1. int main()
  2. {
  3. int x=0,i=0;
  4. scanf("%d",&x);
  5. for(i=0; i<20; i++)
  6. {
  7. x = x+20;
  8. printf("%d\n",x);
  9. }
  10. return 0;
  11. }

    Answer

    21

    Approach

    Count the number of I/O operations performed by the program. Each completed I/O operation causes the process to leave the I/O queue and re-enter the ready queue. Exclude the initial entry into the ready queue when the process first starts.

    The process performs 21 I/O operations in total: one scanf and twenty printf calls. Each completed I/O causes exactly one return to the ready queue, and the initial ready-queue entry is not counted. Hence the required number is 21.

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.