I have a shared library(.so) that I preload before executing an application and I have a few global data structures in the shared library that the application uses. The appl
If you only want to share the data with and among descendent processes (and not with arbitrary processes that are started up seperately, that just happen to link to the same shared library), then the easiest way to do this is have the library create a mapping with mmap() in a constructor function (that is called when the library is initially loaded in the parent process).
Pass the MAP_ANONYMOUS and MAP_SHARED flags to mmap - this will mean that child processes that inherit the mapping will have a mapping that is shared with the parent (and the other children). The library should then store data structures to be shared within that mmaped memory segment (just as if it was memory returned from malloc). Obviously you may need some kind of locking.
Constructor functions for libraries can be indicated using the gcc __constructor__ function attribute.
You don't need to worry about cleaning-up this kind of shared memory - when the last process with an anonymous mapping exits, the memory will be cleaned up.