In general, inter-process communication is a mechanism that allows processes to communicate with each other. The IPC methods vary depending on the operating systems we rely on.
There are two ways where a process can communicate,
- Shared memory
- Message passing
IPC Mechanisms in windows
- Data copy
- File mapping
- Mail slots
- Windows sockets
Selecting the correct IPC that matches your need depends on a few of the following questions,
- Should the application be able to communicate with other applications running on other computers on a network, or is it sufficient for the application to communicate only with applications on the local computer?
- Should the application be able to communicate with applications running on other computers that may be running under different operating systems?
- Should the application communicate with many different applications in a general way, such as allowing cut-and-paste operations with any other application, or should its communications requirements be limited to a restricted set of interactions with specific other applications?
- Is performance a critical aspect of the application? All IPC mechanisms include some amount of overhead.
- Should the application be a GUI application or a console application? Some IPC mechanisms require a GUI application.
- Both the applications should support the clipboard for those data formats that they understand.
- For example, a text editor or word processor should at least be able to produce and accept clipboard data in pure text format.
- Data copy enables an application to send information to another application using the wm_copydata message.
- The data sent is read-only for the receiving application. It works only for the processes running on the same computer.
- It sends messages between applications that share data and uses shared memory to exchange data between applications.
- Applications can use the DDE protocol for one-time data transfers and for continuous exchanges.
- DDE is not as efficient as newer technologies. However, you can still use DDE if other IPC mechanisms are not suitable or if you must interface with an existing application that only supports DDE.
- Allows one-way and bi-directional communication between applications. It uses shared memory for data sharing.
- File mapping can be used only between processes on a local computer; it cannot be used over a network.
- Mail slots:
- Mail slots provide one-way communication. A process can be both a mail slot server and a mail slot client, so two-way communication is possible using multiple mail slots.
- Mail slots offer an easy way for applications to send and receive short messages. They also provide the ability to broadcast messages across all computers in a network domain.
- Allows two-way communication. Two types of pipes are available. Named and anonymous pipes.
- Named pipes are used to transfer data between unrelated process where anonymous is used between processes on a same computer.
- RPC enables applications to call functions remotely. RPC operates between processes on a single computer or on different computers on a network.
- Applications that use RPC are able to communicate with applications running with other operating systems that support DCE (Distributed Computer Environment).
- Windows Sockets (Winsock) enables programmers to create advanced Internet, intranet, and other network-capable applications to transmit application data across the wire, independent of the network protocol being used.
- For example: peer to peer such as chat applications / client-server models.
The selection of an IPC completely depends on the process specifications. In general, shared memory will perform faster than the message passing because in shared memory it relies only a single time on the kernel for memory creation but in message passing It is time consuming as it is implemented through kernel intervention.
Each has its own pros and cons like shared memory can be used for local process and message passing can be used for remote process, etc.