![]() |
Shared Memory is a concept of Operating Systems and is mainly used in Inter-process Communication. If two processes want to share data with each other, they need some intermediate medium to do so and this is where shared memory comes into the picture. What is a Shared Memory?Every process has a dedicated address space in order to store data. If a process wants to share some data with another process, it cannot directly do so since they have different address spaces. In order to share some data, a process takes up some of the address space as shared memory space. This shared memory can be accessed by the other process to read/write the shared data. Working of Shared MemoryLet us consider two processes P1 and P2 that want to perform Inter-process communication using a shared memory. P1 has an address space, let us say A1 and P2 has an address space, let us say A2. Now, P1 takes up some of the available address space as a shared memory space, let us say S1. Since P1 has taken up this space, it can decide which other processes can read and write data from the shared memory space. For now, we will assume that P1 has given only reading rights to other processes with respect to the shared memory. So, the flow of Inter-process communication will be as follows:
![]() Working of shared memory Now, let us assume that P1 has given write rights to P2 as well. So the communication will shown in the below diagram: ![]() Working of shared memory Since P1 took up the space for shared memory i.e. since process P1 is the creator process, only it has the right to destroy the shared memory as well. Use Cases of Shared Memory
Advantages
Disadvantages
ConclusionShared memory is a way for multiple processes to access the same memory space, making it easy to share data. This approach allows different programs to communicate and exchange information quickly and efficiently, helping them work together better. Shared memory is an efficient way for Inter-process communication and allows process to exchange data seamlessly. But it can pose several issues if proper synchronization and authorization techniques are not implemented. Frequently Asked Questions on Shared Memory – FAQsWhat is shared memory and how is it used in Inter-process communication?
What is Mutual Exclusion in shared memory?
How to ensure security of shared memory segments?
|
Reffered: https://www.geeksforgeeks.org
Computer Subject |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 17 |