We can create and attach a shared memory to a process using shmget() and shmat(). What will happen if we don't destroy and detach the shared memory in Ubuntu OS ? According to my understanding it will still exist in the physical memory until the system is restarted, but why is that ? I mean we can load the physical memory with many shared memory blocks through creating multiple of shared memory blocks and this can fill up the physical memory inefficiently ???

  • 1
    Your question is incomplete. "If we don't destroy and detach the shared memory" and what else happens? The processes attached to the shared memory continue to run? Or they exit? What is the scenario you're asking about?
    – Sotto Voce
    Mar 20 at 23:01
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Mar 21 at 4:18

1 Answer 1


From an implementation perspective, it's not much different from a file system inside a ramdisk, and this is how Linux implements it.

If you do not delete a file you created before exiting your program, the file will continue to exist and consume resources.

SystemV SHM is rarely used, and the only reason to do that is that it guarantees that the mapping will be backed by anonymous memory, and not generate disk writes on change, and do so in a portable way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .