Where is shared memory belongs to ? Which means it is owned by each individual process like stack and heap. So, other program cannot able to access the stack of some other program. Or it is a common segment of memory which is used by any number of process. The below figure shows my question diagramatically.
Figure 1:
----------------- ----------------- -----------------
| stack | | stack | | stack |
| | | | | |
| Shared m/y | --->| Shared m/y |<--- | Shared m/y |
| | | | | | | |
| heap | | | Heap | | | Heap |
| | | | | | | |
| Data segment | | | Data segment | | | Data segment |
| | | | | | | |
| text |___| | text | |___| text |
----------------- ----------------- -----------------
Process 1 Process 2 Process 3
(OR)
Figure 2:
-----------------------------------------
| |
| |
| Shared Memory |<--
------->| | |
| | | |
| ----------------------------------------- |
| ^ |
| | |
----------------- ----------------- -----------------
| stack | | stack | | stack |
| | | | | |
| heap | | Heap | | Heap |
| | | | | |
| Data segment | | Data segment | | Data segment |
| | | | | |
| text | | text | | text |
----------------- ----------------- -----------------
Process 1 Process 2 Process 3
In Figure 1, Each process have a segment of shared memory within the address space of a process. On that shared memory of process 2 is accessed by process 1 and process 3. In Figure 2, the shared memory is a segment of memory which is accessed by all the processes. So, in above two scenario, which is used by process for shared memory segment.
