In the producer process, I have the following.
say
- MEMKEY is key_t 234500, and
*shared_ring is a pointer to the data structure (donut_ring) that is being shared.
int shmid, semid[3];
if((shmid = shmget (MEMKEY, sizeof(struct donut_ring), IPC_CREAT | 0600)) == -1){ perror("shared get failed: "); exit(1);
}
if((shared_ring = shmat (shmid, NULL, 0)) == (void *)-1){ perror("shared attach failed: "); sig_handler(-1);
}
The consumer and producer programs are suppose to be in separate files.
How can each consumer find the shared memory id created by the producer, and attach the segment to their address space?
Do I need to call the shmat shmid again in the consumer file, and for each consumer process that is forked? wouldn't it create a new one instead of using the one?