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?
- A. 9
- B. 15
- C. 13
- 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
- Reference string: 2, 3, 4, 1, 2, 3, 1, 5, 2, 3, 4, 1, 5. How many page faults does FIFO give with 3 frames and with 4 frames, and LRU with…
- Reference string: 2, 7, 2, 4, 1, 7, 3, 2, 4, 5, 1, 2, 7, 3, 5, 2. Three frames, initially empty, use LFU replacement: the victim is the…
- Five processes P0-P4 share four resource types A, B, C, D. Allocation: P0 (0,1,0,1), P1 (2,0,0,1), P2 (1,1,1,0), P3 (0,0,2,1), P4…
- Use the same state: Allocation P0 (0,1,0,1), P1 (2,0,0,1), P2 (1,1,1,0), P3 (0,0,2,1), P4 (1,0,1,0); Max P0 (3,2,2,2), P1 (2,1,1,3), P2…
- A system with resource types A, B, C (several instances each) runs the deadlock-detection algorithm. Allocation: P0 (0,1,0), P1 (2,0,0)…
- Shared int x = 1. Thread T1 executes x = x + 1; twice; thread T2 executes x = x 2; once. Each statement compiles to a load of x into a…