Operating System Interview Questions · Question 22

What is a page fault, and how does the OS handle it?

Interview preparation resource from Gate Smashers.

Interview-ready answer

A page fault is an exception raised when the current page-table mapping cannot complete a memory access. The OS validates the access, obtains the page if valid, updates the mapping and restarts the instruction.

Operating System Interview Questions diagram explaining What is a page fault, and how does the OS handle it
Understand it clearly

The fault may represent a valid demand-paged access, a write to a copy-on-write page, a permissions violation or an invalid address. The CPU records the faulting address and transfers control to the kernel's page-fault handler.

For a valid non-resident page, the OS finds a free frame or selects a victim, schedules storage I/O, updates the page table and invalidates any stale TLB entry. The blocked process later restarts the same instruction. An invalid or forbidden access normally causes a signal, exception or process termination.

Not every page fault is an error. A valid demand-page fault is part of normal virtual-memory operation, while an invalid address fault indicates that the process accessed memory outside its permitted mappings and normally leads to a protection signal or termination.