From: Vladimir Jovic on 14 Jul 2010 04:02 Ani wrote: > Hi, > > I have a shared library with a global structure to store status and > some other information. The problem is a every process trying to > access this library gets a local copy of this structure. Is it > possible to have only a single instance of this structure, > irrespective of the number of processes accessing this library, so > that I can share the data ? Is there a linker option or any other away > through which I can achieve this ? > 1) create a file and mmap() 2) use shared memory
From: David Schwartz on 14 Jul 2010 14:11
On Jul 4, 10:52 pm, Ani <anirudhgha...(a)gmail.com> wrote: > I have a shared library with a global structure to store status and > some other information. Global to what? If two processes are using your library on two different machines, should they share the structure? What if they're on opposite sides of the planet? > The problem is a every process trying to > access this library gets a local copy of this structure. Well of course. There's no mechanism for them to share it. > Is it > possible to have only a single instance of this structure, > irrespective of the number of processes accessing this library, so > that I can share the data ? Is there a linker option or any other away > through which I can achieve this ? That would be quite literally impossible. You are asking for two processes to share data knowing only that they've both mapped the same library. How do you even know any mechanism *exists* for them to do that? What if the library is in a read-only network share mounted by two machines, each behind their own NAT? > I cannot do away with this structure and neither can I have a FS based > solution as the reads are writes to this structure are frequent (using > a flash storage). As you point out, there may be quite literally *no* way to do this. > Looking for some ideas/advice on how to handle this. What is your outer problem? Why are you trying to force two machines to communicate with each other despite no interest on the part of either machine in doing so? DS |