Shared library in C with two applications

In the case of a shared library between two applications, does each application use its own copy of the library at runtime? If they use the same library instance, what happens to global variables inside the library?

+4
source share
3 answers

Each program creates a new library instance in its own memory space. They are not shared, and 2 programs will not see each other.

See how dynamic libraries load: http://eli.thegreenplace.net/2011/08/25/load-time-relocation-of-shared-libraries

, , , .

+1

. Unix- , , ( ), , - ( ).

+3

Unix- , , , .

However, the page tables that display the library data section are processed using a mechanism Copy on Write. As soon as you try to write a global variable, the OS will create a specific copy of the page containing this variable and reconfigure the process page table accordingly.

+2
source

All Articles