How to share global variables in a shared library(.so) across instances of the same process that use the shared library in Linux?

后端 未结 3 1594
南旧
南旧 2020-12-16 23:10

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

3条回答
  •  渐次进展
    2020-12-17 00:14

    How about creating a simple pipe in a known directory location, then get other processes to fopen the pipe for reading/writing a la fread/fwrite respectively, to share data...the tricky part is ensuring that the data is passed through the pipe in a manner not to cause corruption in this case. The above you mentioned using shared memory shm_ and mmap is tied to the process, when you fork code, that's no problem since the fork'd code is part of the original process! Hope this helps.

    Best regards, Tom.

提交回复
热议问题