Not certain if this is the right place to ask this. I need to get two processes to use the same data. Process 1 reads text files, parses them and creates linked lists (structures).before this process terminates it display all the lists to prove the data has been loaded correctly. This works, After process 1 exits, process 2 starts. It attaches to the shared memory segment still in memory. The problem is how to get the segment to always attach at the same address used by process 1, ever time process 2 starts. Reason is that the head of each linked list is a fixed offset from the start of shared memory segment. When p2 walks the chain by setting current value pointer to the next, it points to junk.
The original (c 1990) code (in C) still runs fine on SCO but bombs out on Debian. I have already tried to use mmap in a test rig but get same results. either way I cannot list my data in the second process.

There is more than one process 2 but only one is active at a time so the basic stripped down problem is as I describe it. Any suggestions please?

8 Years
Discussion Span
Last Post by spirals

I think the process that creates the shared memory must stay alive until all other processes are done using it. When the creating process dies the os deletes the shared memory. Here is a description for Solaris, which is probably identical to the work I've done with IBM unix.

But, I could be wrong about that too.


Thanks for your reply. I can see with ipcs, the shared memory segment is still there when proc1 exits. I can get proc2 to attach the segment so it is not deleted the attach is not always at the required (same) address.

Process 1 will only run when the data changes.so not very often process 2 reads the data, starts lots of things bit like a micro O/S so it is not possable to keep proc1 alive.

I ported my code (in C of course) from SCO to Solaris around 1997/98 and did not have a problem, worked first time ok with Solaris .8 (x86) So this is a "new problem" for me. specific to the current Debian/linux port.

The code and the logic dates from 1991. The SCO stuff as afar as I am aware is still in use on around 200 nodes.

I can see with ipcs, the shared memory segment is still there when proc1 exits.

I can get process 2 to attach the segment but not always at the required (same) address. I have SHM_RND set and the address (for testing) as (SHMLBA * 0xB7E3B) , as this is the address shmat() chose first time I ran the test rig with an address of NULL.. . I suspect I may have hit a limitation of Debian/Linux but am a relative novice with Linux and have not done any porting since 2001 so I am slightly rusty. Hi!

My difficulty is that if the attachment address is wrong, the pointers in the linked list are then invalid, as the list head is different. To get round this the code will becomes a real mess. As I will have to revert to lot of pointer arithmetic, calculating the links one by one down the chain. Leaving the code as clear as mud for the guy who will maintain it!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.