When programs are written, programmers take great care to make sure that code is not needlessly repeated. Subroutines to handle particular functions are written and used wherever possible. Subroutines that are useful to many programs are gathered together into libraries. These libraries are shareable so that running programs do not load several copies of the same code into memory. Instead only one copy of the code is loaded and all of the programs share that copy.
Virtual memory makes it easy for processes to share memory as all memory accesses are decoded using page tables. For processes to share the same virtual memory, the same physical pages are referenced by many processes. The page tables for each process contain the Page Table Entries that have the same physical PFN.
Figure: Sharing Physical Memory Between Processes
Figure shows two processes that each have physical PFN 1 in their virtual memory map.