Bird
Raised Fist0
Operating Systemsknowledge~20 mins

Demand paging in Operating Systems - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Demand Paging Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What happens during a page fault in demand paging?

In demand paging, when a program accesses a page not currently in physical memory, a page fault occurs. What is the immediate action taken by the operating system?

AThe OS loads the required page from secondary storage into physical memory.
BThe OS terminates the program immediately due to illegal memory access.
CThe OS ignores the request and continues execution without loading the page.
DThe OS swaps out all pages to free memory before loading the requested page.
Attempts:
2 left
💡 Hint

Think about what the OS must do to allow the program to continue after accessing a missing page.

📋 Factual
intermediate
2:00remaining
Which component keeps track of pages currently in physical memory?

In demand paging, which data structure does the operating system use to know which pages are loaded in physical memory?

AProcess control block
BFile allocation table
CInterrupt vector table
DPage table
Attempts:
2 left
💡 Hint

This structure maps virtual addresses to physical addresses.

🔍 Analysis
advanced
2:00remaining
Why can demand paging improve system performance?

Demand paging loads pages only when needed. Which of the following best explains how this improves system performance?

AIt duplicates pages in memory to speed up access times.
BIt preloads all pages before execution, ensuring no delays during program run.
CIt reduces the amount of physical memory used by loading only necessary pages, decreasing disk I/O and speeding up execution.
DIt disables virtual memory, allowing direct access to physical memory.
Attempts:
2 left
💡 Hint

Consider how loading fewer pages initially affects memory and disk usage.

❓ Comparison
advanced
2:00remaining
Difference between demand paging and pre-paging

Which statement correctly contrasts demand paging with pre-paging?

ADemand paging loads pages only when referenced; pre-paging loads pages before they are referenced based on prediction.
BDemand paging loads all pages at program start; pre-paging loads pages on demand.
CDemand paging uses no page table; pre-paging uses a page table.
DDemand paging swaps out pages immediately; pre-paging never swaps pages.
Attempts:
2 left
💡 Hint

Think about when pages are loaded in each method.

❓ Reasoning
expert
2:00remaining
What is the impact of thrashing in a demand paging system?

Thrashing occurs when a system spends more time handling page faults than executing processes. What is the main cause of thrashing in demand paging?

AThe CPU clock speed is too high, causing rapid page faults.
BThe working set of a process is larger than the available physical memory, causing constant page replacements.
CThe disk is too fast, leading to excessive page loading.
DThe page table is corrupted, causing incorrect page mappings.
Attempts:
2 left
💡 Hint

Consider what happens when the memory needed by a process exceeds what is available.

Practice

(1/5)
1. What is the main purpose of demand paging in operating systems?
easy
A. To load pages into memory only when they are needed
B. To load all program pages into memory before execution
C. To increase the size of physical memory
D. To prevent any page faults during program execution

Solution

  1. Step 1: Understand demand paging concept

    Demand paging means loading pages only when the program tries to use them, not before.
  2. Step 2: Compare options with concept

    To load pages into memory only when they are needed matches this idea, while others describe different or incorrect behaviors.
  3. Final Answer:

    To load pages into memory only when they are needed -> Option A
  4. Quick Check:

    Demand paging = load pages on demand [OK]
Hint: Demand paging loads pages only when accessed [OK]
Common Mistakes:
  • Thinking all pages load before execution
  • Confusing demand paging with increasing memory size
  • Assuming demand paging prevents all page faults
2. Which of the following is the correct description of a page fault in demand paging?
easy
A. When all pages are loaded into memory at once
B. When the CPU finishes executing all instructions
C. When the operating system shuts down
D. When a program tries to access a page not currently in memory

Solution

  1. Step 1: Define page fault in demand paging

    A page fault occurs when a program accesses a page that is not in physical memory.
  2. Step 2: Match definition with options

    When a program tries to access a page not currently in memory correctly describes this event; others describe unrelated events.
  3. Final Answer:

    When a program tries to access a page not currently in memory -> Option D
  4. Quick Check:

    Page fault = access missing page [OK]
Hint: Page fault happens on missing page access [OK]
Common Mistakes:
  • Confusing page fault with program completion
  • Thinking page fault happens during shutdown
  • Believing page fault means all pages loaded
3. Consider a system using demand paging. If a program accesses pages in this order: 2, 4, 2, 5, 4, which pages cause page faults assuming none are initially in memory?
medium
A. No page faults occur because pages are preloaded
B. Pages 2, 4, and 5 cause page faults
C. Pages 2 and 5 cause page faults, but not 4
D. Only page 2 causes a page fault

Solution

  1. Step 1: Identify initial memory state and page accesses

    No pages are in memory initially. Access order is 2, 4, 2, 5, 4.
  2. Step 2: Determine which accesses cause page faults

    First access to page 2 causes a fault (not in memory). Then page 4 causes a fault. The second access to page 2 is in memory, no fault. Access to page 5 causes a fault. Last access to page 4 is in memory, no fault.
  3. Final Answer:

    Pages 2, 4, and 5 cause page faults -> Option B
  4. Quick Check:

    First access to new pages = page fault [OK]
Hint: First access to each new page causes fault [OK]
Common Mistakes:
  • Assuming repeated pages cause faults
  • Thinking pages preload automatically
  • Ignoring initial empty memory state
4. A system using demand paging is experiencing frequent page faults. Which of the following could be a likely cause?
medium
A. The program accesses many pages not yet loaded
B. The CPU clock speed is too high
C. The hard disk is disconnected
D. The program is very small and fits in memory

Solution

  1. Step 1: Understand causes of frequent page faults

    Frequent page faults happen when a program accesses many pages not currently in memory.
  2. Step 2: Evaluate options for likely cause

    The program accesses many pages not yet loaded matches this cause. CPU speed or disk disconnection do not directly cause page faults. A small program fitting in memory would cause fewer faults.
  3. Final Answer:

    The program accesses many pages not yet loaded -> Option A
  4. Quick Check:

    Many new page accesses = frequent faults [OK]
Hint: Many new pages accessed cause faults [OK]
Common Mistakes:
  • Blaming CPU speed for page faults
  • Confusing hardware issues with paging faults
  • Assuming small programs cause many faults
5. In a demand paging system, if the page replacement algorithm always removes the page that was least recently used, what is the main benefit of this approach?
hard
A. It increases the total number of pages in memory
B. It prevents any page faults from occurring
C. It reduces the number of page faults by keeping frequently used pages in memory
D. It loads all pages into memory before execution

Solution

  1. Step 1: Understand least recently used (LRU) page replacement

    LRU removes the page not used for the longest time, keeping frequently used pages in memory.
  2. Step 2: Identify benefit of LRU in demand paging

    This reduces page faults by avoiding removal of pages likely to be used soon.
  3. Final Answer:

    It reduces the number of page faults by keeping frequently used pages in memory -> Option C
  4. Quick Check:

    LRU keeps frequent pages, reduces faults [OK]
Hint: LRU keeps frequent pages, lowers faults [OK]
Common Mistakes:
  • Thinking LRU increases memory size
  • Believing LRU prevents all faults
  • Confusing LRU with preloading all pages
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard