Use of shared memory accross processes ..

Posted on 1999-01-05
Last Modified: 2013-12-06
I am using shared memory in my application. The shared memory will be accessed by many processes. In the shared memory, I build simple linked lists. Assume that Process A is building this linked list and Process B
will read the linked list at a later point of time.
Consider Process A has built this :
            --------------       --------------
           |         |  .--|--->|         |  .--|-----
            --------------       --------------       |
                 Node 1              Node 2           -

My question is will Process B understand the pointer
stored in Node 1 (when it tries to traverse the linked list)? Because that pointer is virtual and
should be understood only by Process A.
Question by:srivatsa_v
LVL 84

Expert Comment

ID: 2008643
I'd make the pointers relative to the shared memory block.

Accepted Solution

elfie earned 100 total points
ID: 2008644
A recommended way of doing is, put all your 'pointers' in a struct at the beginning of the shared memory. Then when building the shared memory, put the offset to the  start of the shared memory inside this struct.

Then for each program working with this shared memory you have to create a local copy inside your program that will contain the real pointers. Once connected to the shared memery you know the starting address of the SM. Then fill up your local copy of the struct of pointers.

When you're only workiing  on HP-UX you can put the pointers inside the shared memory, as the shared memory will have the same starting for all connecting programs.
When working on other platforms, the SM can received different addresses depending on the size(data/code) of the connect program. So for these OS's it needed that you have a local copy of the pointers.

So the most generic way is add a header to your SM, that contains the offset to each part inside the SM, and when connecting to the SM, fill a local struct with pointers, adding the offset the start address of the SM

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question