Computer Sciences > GATE 2025 SET-1 > Process Management
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)

Correct : 21

Explanation:
To determine how many times the process enters the ready queue during its lifetime (excluding its initial entry), we need to track every time it transitions from the Waiting/Blocked (I/O) State back to the Ready State.

1. Identify the I/O Operations in the Code:
There are two standard library functions in the code segment that perform I/O operations:
scanf("%d", &x); — Executed 1 time before entering the loop.
printf("%d\n", x); — Executed inside a for loop that runs exactly 20 times (from i = 0 to i < 20). Therefore, this is executed 20 times.

Total number of I/O operation requests = 1 + 20 = 21.

2. Analyze State Transitions for Each I/O:
According to the problem constraints:
• A process goes into the I/O queue whenever an I/O operation is performed.
• A context switch occurs whenever the process requests an I/O (moving from Running → Waiting).
• A context switch also occurs whenever the process returns from an I/O (moving from Waiting → Ready).

Each of the 21 I/O requests follows this lifecycle sequence:
Running(Requests I/O)I/O Queue (Waiting)(I/O Completes)Ready QueueRunning

3. Calculate Total Entries into the Ready Queue:
• The scanf statement causes the process to enter the ready queue exactly 1 time after its I/O completes.
• The printf statement inside the loop causes the process to enter the ready queue exactly 20 times across all iterations.

Total entries into the ready queue = 1 + 20 = 21.

Similar Questions

Consider the following program snippet. Assume that the program compiles and runs successfully. Further, assume that the fork() system call is always successful...
#1543 Fill in the Blanks
A palindrome is a word that reads the same forwards and backwards. In a game of words, a player has the following two plates painted with letters. From...
#1 MCQ
Which number does not belong in the series below? 2, 5, 10, 17, 26, 37, 50, 64
#4 MCQ

Related Topics

No tags found

Unique Visitor Count

Total Unique Visitors

Loading......