Global variable in .so library

Say the x.so library has a global variable y that is manipulated by a function (say fun1 ) in the library.

When the p1 process is loaded into RAM, the code of which uses the fun1 function from the x.so library, the x.so library will be loaded into the RAM (if not already specified) using ld.so, and the symbol function will be enabled before the program starts.

Now where is this global variable created. Is he in the process of p1 ?

What happens when another p2 process also uses fun1 (which performs operations on y )?

+6
source share
2 answers

The processes will receive their personal copies of y , and when exec called, it will be replaced with a new copy. It will be in the library data segment.

+6
source

Each process creates its own instance of the variable y when loading the library at startup until it reaches the main entry point.

+2
source

All Articles