Process - Shared (Virtual) Memory (SHM)

1 - About

Shared memory is a way to shared state between process.

The structure that is shared is called a segment.

Shared memory, as its name implies, is a method to “share” data between processes. Both processes define the same memory area as “shared”, and they can then exchange information simply by writing into it. This (used to be, and still is somewhat) faster than the alternative of sending network or pipe-based messages between processes.

If you see the memory as a mean of storing data, a file on a file system can be seen as shared memory (ie shared file).

It is difficult to account for shared memory. Does it belong to one process? Both? Neither? If we naively sum the memory belonging to multiple processes, we grossly “over-count”.

As the name implies, the Shared (Virtual) Memory refers to virtual memory that are shared by more than one process and then can be used by multiple programs simultaneously.

Although virtual memory allows processes to have separate (virtual) address spaces, there are times when you need processes to share memory.

Shared memory (SHM) is another method of interprocess communication (IPC) whereby several processes share a single chunk of memory to communicate.

Shared memory provides the fastest way for processes to pass large amounts of data to one another.

3 - Linux

  • In Linux, shared memory looks like a regular file system - /dev/shm (but is under the hood Tmpfs).
  • Linux supports the Unix TM System V shared memory IPC.

4 - Documentation / Reference

code/process/shared_memory.txt · Last modified: 2018/12/09 16:58 by gerardnico