OS & Hardware

What generally happens when a program accesses an address the OS has not allocated?

  1. AThe CPU automatically adds new physical memory for that address
  2. BThe access is ignored, and the program continues to the next instruction as if nothing happened
  3. CA page fault occurs, and the OS judges it an illegal access and stops the program
Show answer and explanation

Answer: C. A page fault occurs, and the OS judges it an illegal access and stops the program

Accessing an unallocated address finds no valid page-table entry, so a page fault occurs. The OS checks whether the address lies in a region the process is allowed to use, and if it is allocated nowhere, it signals an error and stops the program (a so-called segmentation fault). This keeps stray pointers from corrupting other processes or the OS. Physical memory is not added automatically, and the access is not silently ignored.

  • A. Physical memory is never added automatically.
  • B. Silently ignoring it would hide the bug.
  • C. Correct. On the page fault, the OS stops the program for an illegal access.
Practice this topic Back to topic

More OS & Hardware questions

  1. In a mechanism that maps a file into memory (such as mmap), what happens when the file's contents are read?
  2. When writing small data one byte at a time, why is accumulating it in a user-space buffer and writing in bulk faster than calling a system call each time?
  3. What is the main purpose of giving a CPU a privileged (kernel) mode and a user mode?
  4. What is the mechanism by which applications ask the OS to perform tasks such as file I/O?
  5. What happens when the ecall instruction at the end of the RISC-V code above executes?