The use of various mechanisms of the IPC

I am a C ++ programmer.

I wanted to know a real-time scenario where we can use different IPC mechanisms, such as PIPE / Named, Shared Memory.

I roughly know where I can use the socket and message queue. But for PIPE / Named PIPE and shared memory, I do not understand.

It is easy to understand the various IPC mechanisms and their use.

Thanks,

+6
c ++ ipc
source share
2 answers

I needed to use Named pipe to communicate with my Erlang Vitual Machine, which worked as a daemon.

I believe that they are slowly being replaced by "socketpairs", because it offers bidirectional communication as opposed to pipes, which is only unidirectional unless we create two different pipes.

Shared memory is still used in large server applications, because it will be the fastest of all other mechanisms in a multiprocessor system, but as a rule, it is difficult to implement it correctly.

And the use of sockets becomes necessary only when communication over the network is required.

Again comes down to one thing: "Use the mechanism that is best suited for the application"

+2
source share

We have software in our company that uses shared memory. It uses it to stream data from one process to other processes. Sockets can be used for this, but since it is a one-to-many relationship, a separate socket must be created for each consumer process, which is not optimal. It is likely that this work will be done on modern computers using a shared file, but this software was developed in the mid-90s, when the disks were quite slow, and this software has fairly strict latency requirements. It uses a kind of circular buffer, where the producer process writes its data. Semaphores are used for synchronization, so other processes will not see partially updated data.

Most modern program threads are usually used in place of several processes that use shared memory.

As for the pipes, the most common for them is the shell:

ps ax | grep java 

I believe that named pipes are mostly replaced by sockets. Even if they still use them, I do not know any of them.

You can also read the related chapter, "The Art of Unix Programming," by Eric Stephen Raymond. It gives a very good overview of Unix IPC methods and their use.

+1
source share

All Articles