GATE 2026 (Session 2)
65 questions
MCQ 35 · MSQ 11 · NAT 191-mark 30 · 2-mark 35
Questions 51–55 of 65
Consider three processes , and running identical code, as shown in the pseudocode below. and are two binary semaphores initialized to and , respectively. is a shared variable initialized to . Each line in the pseudocode is executed atomically.
Pseudocode of P1, P2, and P3
Which of the following patterns is/are possible to be generated as an outcome of the execution of these three processes?
Pseudocode of P1, P2, and P3
Wait(A);
Print(*);
X = X+1;
If (X == 2)
{
Print($);
Signal(B);
}
Signal(A);
Wait(B);
Print(#);
Signal(B); Assume that any of the three processes can start to execute first and context switching can happen between these processes at any arbitrary time and in any arbitrary order. Which of the following patterns is/are possible to be generated as an outcome of the execution of these three processes?
One or more options are correct.
Answer: (A), (B), (C)
Semaphore (initial value ) works as a mutex for the critical section. The section prints "*", increments and does the check. So the three processes enter this section one at a time. Exactly one of them, the second to enter, sees . That process prints "" and then signals . The third process cannot even try this section until the second one has released . This happens only after the second one prints "". So the global order is forced to be: , that is, two stars, then the dollar, then the third star. A pattern like (three stars before the dollar) can never occur.
After the dollar, semaphore has exactly one permit. This starts a chain. Each process that takes the permit with prints "". It then gives the next permit with its own , which lets the next process go. The remaining (third) star can come in at any point of this "" chain before that third process itself joins the chain. That means before any , after exactly one , or after exactly two symbols. It can never come after all three, because the third process must finish its own star and critical section before it can join the chain at all.
Answer: **$*###, **$#*##, and **$##*# are all possible; ***$### is impossible.
After the dollar, semaphore has exactly one permit. This starts a chain. Each process that takes the permit with prints "". It then gives the next permit with its own , which lets the next process go. The remaining (third) star can come in at any point of this "" chain before that third process itself joins the chain. That means before any , after exactly one , or after exactly two symbols. It can never come after all three, because the third process must finish its own star and critical section before it can join the chain at all.
Answer: **$*###, **$#*##, and **$##*# are all possible; ***$### is impossible.
Consider a system with a processor and a KB direct mapped cache with block size of bytes. The system has a MB physical memory. Four words , and S are accessed by the processor in the same order times. That is, there are a total of memory references in the sequence
Assume that the cache memory is initially empty. The physical addresses of the words are given below ( word byte).
Which of the following statements is/are true?
Note: and
Assume that the cache memory is initially empty. The physical addresses of the words are given below ( word byte).
Which of the following statements is/are true?
Note: and
One or more options are correct.
Answer: (A), (B)
Block size 16 bytes, so the offset is 4 bits. Lines: , so the index is 8 bits. 16 MB memory means 24-bit addresses, so the tag is bits. In hex, the last digit is the offset, the next two digits are the index, and the first three digits are the tag.
P = 0x845B32: tag 845, index B3, offset 2
Q = 0x845B26: tag 845, index B2, offset 6
R = 0x845B36: tag 845, index B3, offset 6
S = 0x846B32: tag 846, index B3, offset 2
So P and R are in the same block. Q uses a different line (index B2). S uses the same line as P and R (index B3) but has a different tag, so S and P/R replace each other.
Run the sequence P, Q, R, S, P, Q, R, S, ...
(A) True. Each S removes the P/R block, so every P is a miss.
(B) True. The block of P was just loaded, so every R is a hit.
(C) False. Q is a miss only the first time; after that its line is never replaced, so Q hits.
(D) False. Each S finds the P/R block in its line, so every S is a miss, not only the first.
Answer: (A), (B)
P = 0x845B32: tag 845, index B3, offset 2
Q = 0x845B26: tag 845, index B2, offset 6
R = 0x845B36: tag 845, index B3, offset 6
S = 0x846B32: tag 846, index B3, offset 2
So P and R are in the same block. Q uses a different line (index B2). S uses the same line as P and R (index B3) but has a different tag, so S and P/R replace each other.
Run the sequence P, Q, R, S, P, Q, R, S, ...
(A) True. Each S removes the P/R block, so every P is a miss.
(B) True. The block of P was just loaded, so every R is a hit.
(C) False. Q is a miss only the first time; after that its line is never replaced, so Q hits.
(D) False. Each S finds the P/R block in its line, so every S is a miss, not only the first.
Answer: (A), (B)
To keep track of free blocks in a file system, one of the two approaches is generally used - using bitmaps (bit vectors) or using linked lists. Consider that the linked list approach is used to keep track of free blocks in a file system. Assume that the disk size is GB , block size is KB , and block numbers used are -bit long. A single pointer of size bytes is used in each block of the list to point to the next block of the list. The number of blocks required to hold the free disk block numbers is ________. (answer in integer)
Note: and
Note: and
Answer: 16417
The disk has blocks in total. Each of these blocks needs one entry of bits ( bytes) for its block number in the free list.
Each list block is one block of bytes. It keeps bytes for the "next" pointer. That leaves bytes for free-block numbers, so each list block holds free-block numbers.
Blocks needed for the list: .
Answer: 16417
Each list block is one block of bytes. It keeps bytes for the "next" pointer. That leaves bytes for free-block numbers, so each list block holds free-block numbers.
Blocks needed for the list: .
Answer: 16417
A system has a Translation Lookaside Buffer (TLB) that has a reach of MB. TLB reach is defined as the total amount of physical memory that can be accessed through the TLB entries. The paging system uses pages of size KB. The virtual address space is GB and physical address space is GB. If each TLB entry stores a -bit process id, page number, frame number, and a -bit control field, then the size of the TLB (in bytes) is ________. (answer in integer)
Note:
Note:
Answer: 1536
The TLB reach the page size the number of TLB entries. So the number of entries is found as:
The virtual address space bytes, so the virtual page number needs bits, where the page size is .
The physical address space bytes, so the frame number needs bits.
One TLB entry holds a -bit PID a -bit page number a -bit frame number a -bit control field. This gives bits, which bytes per entry.
Total TLB size: bytes.
Answer: 1536
The virtual address space bytes, so the virtual page number needs bits, where the page size is .
The physical address space bytes, so the frame number needs bits.
One TLB entry holds a -bit PID a -bit page number a -bit frame number a -bit control field. This gives bits, which bytes per entry.
Total TLB size: bytes.
Answer: 1536
Consider contiguous allocation of physical memory to processes using variable partitioning scheme. Suppose there are holes in the memory of sizes , , and . Assume that no two holes are adjacent. Two processes of size and of size arrive in that order, and they are allocated memory using the best-fit technique. After allocating space to and , the number of holes of size less than is ________. (answer in integer)
Note:
Note:
Answer: 3
Best-fit chooses the smallest hole that is big enough for the request.
Holes at the start (KB): .
P1 (16 KB): among the holes , the smallest is . P1 goes in this hole, and a hole of KB is left. The holes are now: .
P2 (9 KB): among the holes , the smallest is the KB hole, which fits exactly. It is used up completely and no hole is left from it. The holes are now: ( holes left).
Now count the holes smaller than KB in . They are KB, KB and KB. That makes holes.
Answer: 3
Holes at the start (KB): .
P1 (16 KB): among the holes , the smallest is . P1 goes in this hole, and a hole of KB is left. The holes are now: .
P2 (9 KB): among the holes , the smallest is the KB hole, which fits exactly. It is used up completely and no hole is left from it. The holes are now: ( holes left).
Now count the holes smaller than KB in . They are KB, KB and KB. That makes holes.
Answer: 3