Mankan <firstname.lastname@example.org> wrote:
My question is :
I have two process, named process1 and process 2 and both these process
communicate through shared memory.
In the process1 I have a buffer, whose pointer is there in the shared
My question is that: Is it possible for the Process2 to use this pointer in
the shared memory to access the content of the
buffer in the Process1.
Any help will be greatly appreciated.
No. The two processes will have different virtual addresses. (They may,
by coincidence have the same virtual addresses for the piece in
question, but that is not guaranteed).
Generally, shared memory is best done with offsets only, using the pointer
within each processes’ virtual address space.
I.e., in process1 and process2, you could have code like:
struct my_data_t *ptr;
ptr = mmap (…);
ptr → member [element]
You cannot have code like:
ptr → member → other_member
because the pointer “member” would need to contain a virtual address
that’s valid in both contexts – not gonna happen.
If that’s what you need to do (i.e., store two or more structures in the
shmem area), then you need to have two pointers:
struct my_data_1_t *p1;
struct my_data_2_t *p2;
p1 → member
p2 → other_member
would be a way of doing it…
Anyway, it’s a long, complicated topic
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.