Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

global variable in a .so library

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

When a process p1 is loaded into RAM whose code is using function fun1 from library x.so, the library x.so will be loaded into RAM (if not already present) by ld.so and the function symbol gets resolved before the program starts executing.

Now where is this global variable created. Is it in process p1 ?

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

like image 627
tez Avatar asked Feb 27 '14 14:02

tez


1 Answers

Processes will get their private copies of y and it will be replaced by a fresh copy when you call exec. It will reside in the library's data segment.

like image 89
Sergey L. Avatar answered Sep 20 '22 01:09

Sergey L.