Deleting shared memory segment with shmctl Deleting shared memory segment with shmctl linux linux

Deleting shared memory segment with shmctl


Your first reasoning is correct. The shared segment will exists until both: it is marked with IPC_RMID and last process detaches.

The purpose of the second fragment is to remind you, that in a solution using shared memory you need to have some process mark it for destruction or it will remain in memory/swap forever. It might be good idea to use IPC_RMID immediately after creating segment.

If you are not sure you have successfully released memory, you can use ipcs program to list remaining segments.