Reputation:
I have a global variable in a shared library(libshared.so).The library is accessed by more than one process and the processes are accessing the global variable present in the library. The problem i am facing is that the update to the global variable(present in shared library) by one process is not reflected to the variable accessed by other independent process.
I searched the web regarding this issue but didn't got any suitable way to rectify this.Also i came to know that only text/code segments are shared and each process gets a local copy of data segment.
Please suggest a solution to implement this requirement.I want to update the global variable in shared library.
Enviornment:-Linux,ARM
Thanks Amit Kumar
Upvotes: 0
Views: 978
Reputation:
If multiple processes use the same shared library, they get the same code segment mapped, but each process gets its own copies of writable data segments. So, "global" here means only global in the context of one process and its address space.
Think about it: any other implementation would be calling for desaster, e.g. errno
in the standard C library is "global", and you definitely don't want to read the error produced by a random other process here.
If this is your own library and you really need to share data between processes, have a look at shared memory (e.g. on linux shmget() et al).
Upvotes: 2