I have a structure:
struct sdata {
int x;
int y;
time_t time;
};
I create shared memory for the structure as follows:
size_t shmsize = sizeof(struct sdata);
shmid = shmget(IPC_PRIVATE, shmsize, IPC_CREAT | 0666);
Then I access the shared memory as follows:
struct sdata *data = shmat(shared.shmid, (void *) 0, 0);
data->time = time(NULL);
My question is pretty simple. Is this the correct way to access / change shared memory? Is this a better approach?
(I use System V semaphores for synchronization, and I did not include this code. I just wanted to make sure that I am changing the shared memory correctly / correctly.)
source
share