views:

34

answers:

2

In Linux, When we are sharing data between 2 or more processes using shared memory, where does the shared memory gets allocated?

Will it become part of process address space at run time? as the process cannot access the memory outside its address space.

Could some one please clarify?

+2  A: 

When you have shared memory, then that memory gets mapped into the virtual address space of each process that shares the memory (not necessarily at the same virtual addresses in each process). The virtual memory manager ensures that the virtual addresses both map to the same physical addresses so that the sharing actually happens.

Adam Rosenfield
Thanks Adam! Will it become part of any of the segments in process address space? like in heap or into data segment?
Teja
A: 

Assuming System V: One process takes memory which is allocated inside its process space and makes it available to others via IPC. The most common way to share it is to map the memory into the other process' virtual address space. In which case they can access the memory as though it was part of their won address space.

henry