📜  IPC中的共享内存模型和消息传递模型之间的区别

📅  最后修改于: 2021-08-27 18:15:33             🧑  作者: Mango

前提条件–进程间通信
1.共享内存模型:
在此IPC模型中,建立了一个共享的内存区域,供数据通信过程使用。该内存区域位于创建共享内存段的进程的地址空间中。要与该进程进行通信的进程应将此内存段附加到其地址空间中。

2.消息传递模型:
在此模型中,进程通过交换消息相互通信。为此,过程之间必须存在通信链接,并且它必须促进至少两个操作的发送(消息)和接收(消息)。消息的大小可以是可变的或固定的。

IPC中的共享内存模型和消息传递模型之间的区别:

S.No Shared Memory Model Message Passing Model
1. Shared memory region is used for communication. Message passing facility is used for communication.
2. It is used for communication between processes on a single processor or multiprocessor systems where the communicating processes reside on the same machine as the communicating processes share a common address space. It is typically used in a distributed environment where communicating processes reside on remote machines connected through a network.
3. The code for reading and writing the data from the shared memory should be written explicitly by the Application programmer. No such code required here as the message passing facility provides mechanism for communication and synchronization of actions performed by the communicating processes.
4. It provides maximum speed of computation as communication is done through shared memory so system calls are made only to establish the shared memory. It is time consuming as message passing is implemented through kernel intervention (system calls).
5. Here the processes need to ensure that they are not writing to the same location simultaneously. It is useful for sharing small amounts of data as conflicts need not to be resolved.
6. Faster communication strategy. Relatively slower communication strategy