Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of Different IPC mechanism

Tags:

c++

ipc

I am a c++ programmer.

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

I roughly know where I can use socket and message queue. But for PIPE/Named PIPE and shared memory I am not getting any idea.

This is just for understanding about different IPC mechanisms and their usage.

Thanks,

like image 490
Vikram Ranabhatt Avatar asked Jan 31 '11 10:01

Vikram Ranabhatt


2 Answers

I needed to use Named pipe for communicating with my Erlang Vitual Machine which was running as a daemon.

I believe they are being slowly replaced by "socketpairs" as it offers bi-directional communication unlike pipes which is only unidirectional unless we create two different pipes.

Shared Memory are still in use in large Server applications as it will be the fastest of all other mechanisms on a multiprocessor system but are usually difficult to implement in the right way.

And use of sockets becomes necessary only when communication across a network is required.

Again it comes down to one thing "Use the mechanism which suits you best for the application"

like image 127
Arunmu Avatar answered Oct 23 '22 17:10

Arunmu


We have some software in our company that uses shared memory. It uses it to stream data from one process to some other processes. Sockets could be used for it, but since it is one-to-many, a separate socket should be created for each consumer process which isn't really optimal. On modern computers using a shared file would probably do the job, but this software was developed in mid-90s when disks were pretty slow, and this software has pretty 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 won't see partially updated data.

In most modern software threads are usually used instead of multiple processes using shared memory, though.

As for pipes, the most common use for them are shell pipes:

ps ax | grep java

I believe named pipes are largely replaced by sockets. Even if they still have their uses, I'm not aware of any of them.

You may also wish to read the relevant chapter of the Art of Unix Programming by Eric Steven Raymond. It gives very nice overview of Unix IPC methods and their uses.

like image 39
Sergei Tachenov Avatar answered Oct 23 '22 18:10

Sergei Tachenov