GateAI
Processes, Threads and IPC

GATE CSE 2025 Set 1 · Q29

NAT1 markEasy

Time

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 ",x); } return 0; }

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 21

Processes, Threads and IPC

When a process performs an I/O operation, it transitions from the Running state to the Waiting/Blocked (I/O) state. Upon completion of the I/O operation, the process transitions from the Waiting state back into the Ready queue.

Let us count the total number of I/O operations performed during the lifetime of this process:

  1. scanf("%d", &x);:

    • This is an input I/O operation executed once.

    • After this I/O completes, the process enters the ready queue 1 time.

  2. for(i=0; i<20; i++) loop:

    • The loop runs for i=0,1,…,19i = 0, 1, \dots, 19, which is exactly 2020 iterations.

    • In each iteration, the output I/O operation `printf("%d

", x);` is executed once. - Thus, there are 2020 output I/O operations. - After each printf operation completes, the process enters the ready queue 1 time, giving 2020 entries into the ready queue.

Total times the process enters the ready queue after initial creation:

Total=1+20=21\text{Total} = 1 + 20 = 21

Therefore, the correct answer is 21.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Processes, Threads and IPC previous year question is Q29 of the GATE CSE 2025 Set 1 paper. Find more GATE CSE PYQs on Processes, Threads and IPC in Operating Systems, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Processes, Threads and IPC PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Processes, Threads and IPC in GATE CSE

Processes, Threads and IPC has 15 GATE CSE PYQs across 13 papers from 2011 to 2026. 3 of them are 1-mark NAT questions like this one, and it is the only one in GATE CSE 2025 Set 1.

How GATE tests Processes, Threads and IPC

More from GATE CSE 2025 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2025 Set 1 · Q29 · NAT

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

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.