How to get address information from the library for sharing between all processes?

In Understanding the Linux Kernel, 3rd Edition, it says:

Shared libraries are especially useful on systems that provide file memory mapping, since they reduce the amount of main memory requested to run the program. When the dynamic linker must associate a shared library with a process, it does not copy the object code, but only maps the memory of the corresponding part of the library file to the process address space. This allows page frames containing machine code for the library to be shared by all processes using the same code. Obviously, sharing is not possible if the program was linked statically. (p. 817)

I'm interested in this, I want to write a little C program to check, given the two pids as input, such as two gedit processes, and then get the address information from the page frames for sharing. Does anyone know how to do this? From this book, I think the bss segment and the text segment of two or more gedit processes are the same, right?

+6
source share
2 answers

These are not the text and bss your gedit (or another) that have the same address, but the contents of the libc.so shared library - and all the other shared libraries used by the two gedit processes.

This, as stated in the cited text, allows the shared library to be ONE copy, and this is the main advantage of the shared library as a whole.

bss is generally not shared as it relates to process data. text sections of two processes running the same executable file on Linux will use the same code.

Unfortunately, proof of this will be viewing the physical display of the pages (the page at address X in process A is located at physical address Y, and the page for address X in process B is also located at physical address Y) within the processes, and this, as far as I know, not easily accessible without getting around inside the OS kernel.

+2
source

See the contents of /proc/*/maps .

0
source

All Articles