how to have a shared variable in library across many applications in linux?
how to have a shared variable in library across all application in linu开发者_运维百科x (c++)?
You can use POSIX shared memory to create a shared memory segment, and place the variable there. You will need to synchronise access to the shared variable using POSIX semaphores.
See the shm_overview(7) and sem_overview(7) man pages to get started.
Likewise, you can use posix shared memory or just mmap() a file and have the variable exist in that area of memory.
The loader will not automatically do this with a special section such as the "shared" one in Win32 DLLs. This is probably not a big deal as it's a bit of an anti-feature anyway.
精彩评论