I allocated a block of shared memory using shmget.
Then I attach the shared memory to process A and process B respectively using shmat. I assume the handles(i.e.,addresses within A and B that are mapped to the actual shared memory) for A and B returned by shmat are different.
Let's assume the handles for A and B are defined as char* p and char* q respectively. My question is if we write an object to the address p + sizeof(anotherObject) within process A, can we expect to get the same object at the address q + sizeof(anotherObject) within process B?
I guess it is the case but am not 100% sure. If so, how is this communication or mapping mechanism being achieved since we know that p + sizeof(anotherObject) and q + sizeof(anotherObject) are referring to different memory locations?
shm_openandmmapfor such a task. They are less restrictive and easier to handle.