CS FundamentalsVery hardProduct company interview · GATE level

Reference string: 2, 7, 2, 4, 1, 7, 3, 2, 4, 5, 1, 2, 7, 3, 5, 2. Three frames, initially empty, are managed by the clock (second-chance) algorithm: a hit sets the page's reference bit to 1; on a fault the hand skips frames whose bit is 1 (clearing the bit and advancing), replaces the first frame whose bit is 0, loads the new page with its bit set to 1, and advances one frame. Empty frames are filled in order. How many page faults occur?

  1. A. 9
  2. B. 15
  3. C. 13
  4. D. 14

Correct answer: D. 14

Trace the hand. Loads 2, 7 (2 is hit and keeps bit 1), 4 fills the frames. Fault on 1: all bits are 1, so the hand clears them all and comes back to replace 2. 7 is a hit. On 3 the hand clears 7's bit and replaces 4; on 2 it replaces 7... continuing, only the references 2 (third), 7 (sixth) hit, giving 16 - 2 = 14 faults - the same as FIFO here, while LRU gives 15 and Optimal 9. Clock approximates LRU, but when every bit is set it degenerates into FIFO, which is what happens on this string.

More Operating Systems questions

Exams that ask this topic