Linkers, Loaders & Executables

When 100 processes use the same shared library, how is physical memory used?

  1. AThe read-only code pages are shared as one copy, while writable data pages are held per process
  2. BBoth code and data have 100 copies, one per process
  3. CEverything, including data pages, is shared, so processes see each other's values
Show answer and explanation

Answer: A. The read-only code pages are shared as one copy, while writable data pages are held per process

The OS maps the shared library into each process's virtual address space so that pages of unchanging code and constants point to the same physical pages. Pages of writable data such as variables are kept separate per process, for example by copying a page when it is first written (copy-on-write). So even with 100 processes, the library's code occupies memory only once.

  • A. Correct. Virtual memory maps the same physical pages.
  • B. Copying the code would defeat the purpose of shared libraries.
  • C. Data is kept separate per process.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. Disassembling an object file shows that an instruction calling the external function printf has a placeholder target such as 0. When is the correct value filled in?
  2. What is the role of a linker script used in embedded development?
  3. On a microcontroller without an OS, what does the start-up code do right after power-on before calling main?
  4. What is the difference between "sections" and "segments" in an ELF file?
  5. Which attack does W^X (never allowing a page to be both writable and executable) make harder?