Code for C library functions - e.g. scanf, printf, etc. can be shared by processes. The library code is called a shared object. The file name reflects this: libc.so.
A shared object is loaded in physical memory once.
The virtual memory of each process has a contiguous segment that is mapped to shared libraries.
A process can create its own segments and segments can be shared or private.
| Process virtual memory | |
|---|---|
| Process-specific data page tables, mm_structs, kernel stack |
|
| Physical memory mapped into kernel's virtual memory |
|
| Kernel code and data | |
| User stack | |
| Shared libraries | |
| <-- brk | |
| Heap | |
| Uninitialized Data | |
| Initialized Data | |
| Program Text | |