Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross platform IPC [closed]

I'm looking for suggestions on possible IPC mechanisms that are:

  • Cross platform (Win32 and Linux at least)
  • Simple to implement in C++ as well as the most common scripting languages (perl, ruby, python, etc).
  • Finally, simple to use from a programming point of view!

What my options are? I'm programming under Linux, but I'd like what I write to be portable to other OSes in the future. I've thought about using sockets, named pipes, or something like DBus.

like image 792
Thomi Avatar asked Sep 13 '08 16:09

Thomi


People also ask

Which is fastest IPC in Linux?

Shared memory is the fastest form of interprocess communication. The main advantage of shared memory is that the copying of message data is eliminated. The usual mechanism for synchronizing shared memory access is semaphores.

Is IPC shared memory?

Inter Process Communication through shared memory is a concept where two or more process can access the common memory. And communication is done via this shared memory where changes made by one process can be viewed by another process.

What are different IPC mechanisms available in Linux system?

Linux supports three types of interprocess communication mechanisms which first appeared in Unix System V (1983). These are message queues, semaphores and shared memory.

What is IPC Unix?

Interprocess communication (IPC) refers to the coordination of activities among cooperating processes. A common example of this need is managing access to a given system resource.


2 Answers

In terms of speed, the best cross-platform IPC mechanism will be pipes. That assumes, however, that you want cross-platform IPC on the same machine. If you want to be able to talk to processes on remote machines, you'll want to look at using sockets instead. Luckily, if you're talking about TCP at least, sockets and pipes behave pretty much the same behavior. While the APIs for setting them up and connecting them are different, they both just act like streams of data.

The difficult part, however, is not the communication channel, but the messages you pass over it. You really want to look at something that will perform verification and parsing for you. I recommend looking at Google's Protocol Buffers. You basically create a spec file that describes the object you want to pass between processes, and there is a compiler that generates code in a number of different languages for reading and writing objects that match the spec. It's much easier (and less bug prone) than trying to come up with a messaging protocol and parser yourself.

like image 120
Douglas Mayle Avatar answered Oct 12 '22 22:10

Douglas Mayle


For C++, check out Boost IPC.
You can probably create or find some bindings for the scripting languages as well.

Otherwise if it's really important to be able to interface with scripting languages your best bet is simply to use files, pipes or sockets or even a higher level abstraction like HTTP.

like image 34
Brian R. Bondy Avatar answered Oct 12 '22 23:10

Brian R. Bondy