Linkers, Loaders & Executables
When 100 processes use the same shared library, how is physical memory used?
- AThe read-only code pages are shared as one copy, while writable data pages are held per process
- BBoth code and data have 100 copies, one per process
- 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.