title: How to coordinate shared memory between 2 processes
body: <p>I have program A and program B. Program A makes a queue that's stored into the shared memory with shmget, then shmat. Process B starts up and then uses the same shmid to obtain the queue that process A made without a problem. Process A (both A and B are running at the same time obviously) then runs a method that modifies a certain element in the queue. When program A does this, the pointer to that memory block gives me a segmentation fault. probably because program B now has the pointer pointing to it I suppose.
  My question is how can I fix this so that program A can edit and read from queue as well as program B. I know that I need some sort of locks but don't know what kind of lock would be best or how to correctly implement this. If you can put up some example code to go along with your explanation that would help a lot. I'm writing all of this in C by the way and process A has 2 keys, one to the queue and another to an array holding all the shmids for every segment allocated in shared memory from Program A to be used by program B to retrieve that information.</p>