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
To phrase this most clearly: you cannot do exactly what you asked. Linux does not support sharing of global variables that are laid out by the linker. That memory will be in unsharable mapped-to-swap space.
A general recipe I can offer is this:
If you really only care about a parent and it's forked children, you can use an anonymous mapping and not bother with the file, and you can store the location of the mapping in a global (which can be read in the children).