I have a structure which looks like:
typedef struct shared_data_t
{
char *key;
char *message;
}shared_data;
I need to share this structure with another unrelated process. I am using POSIX shared memory with shm_open()/mmap() to achieve this. However, my target process is not getting the shared data and its dieing with SIGSEGV, which is obvious. It will be great if someone help me on this, specially what happens while sharing pointers between two processes with shared memory (with shm_open and mmap).
For a structure like,
typedef struct shared_data_t
{
char key[8];
char message[32];
}shared_data;
it works all fine!
There is a note about this in the Linux man page for shmat
:
Using shmat() with shmaddr equal to NULL is the preferred, portable way of attaching a shared memory segment. Be aware that the shared memory segment attached in this way may be attached at different addresses in different processes. Therefore, any pointers maintained within the shared memory must be made relative (typically to the starting address of the segment), rather than absolute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With