First of all thank you for answering my post, I really appreciated your help!
I run my program a few times, then checked the ipc status with ipcs (that's REALLY useful
The output shows that each semaphore I've used in my program still exists!! Not only, I've also discovered that even shared memory areas aren't deallocated when the program is terminated: they're still in the list provided by ipcs, with 0 processes attached to them.
Basically, detachment is successful, but shared memory isn't really deallocated. Any idea?
This is how I call shmget, shmat, shmctl (to deallocate when detachment is done) and shmdt:
coord_buf_s_id = shmget (IPC_PRIVATE, COORD_DIM * sizeof(pos), IPC_CREAT | S_IRUSR | S_IWUSR );
coord_buf = shmat ( coord_buf_s_id, NULL, SHM_RND );
shmctl (coord_buf_s_id, IPC_RMID, NULL);
Since ipcs reports no precess is attached to shared segments, I suppose there's some kind of problem with shmctl...
As for semaphores, there's no need to attach/deattach, so I just call a
coord_mutex = semget (IPC_PRIVATE, 1, IPC_CREAT | S_IRUSR | S_IWUSR );
when program begins, then call
semctl (coord_mutex, 1, IPC_RMID, arg);
before the last process of the program exits.
Is my code OK?
Thank you in advance