I have a struct:
struct sdata {
int x;
int y;
time_t time;
};
I create shared memory for the struct as follows:
size_t shmsize = sizeof(struct sdata);
shmid = shmget(IPC_PRIVATE, shmsize, IPC_CREAT | 0666);
Then I access the shared memory like this:
struct sdata *data = shmat(shared.shmid, (void *) 0, 0);
data->time = time(NULL); // function returns the current time
My question is pretty simple. Is this the right way to access/modify shared memory? Is this the best approach?
(I am using System V semaphores for synchronization and I haven't included that code. I just wanted to make sure I am accessing/modifying the shared memory correctly.)