Communication between Linux programs

How do I implement communication between Linux programs written in C? In particular, I want the following:

My program can work in multiple instances. At startup, I want my program to detect all other instances of my program that are already running, and then it should be able to send them a text string. On the other hand, I also want instances that are already running to be notified that the new instance is running, and they should also be able to send a text string to the new instance.

Can someone point me to some APIs that can be used to implement such software on Linux? On Windows, I can simply list all the windows, check their class names to find out all instances of my program, and then register my own message with the system, which I can use to send data to them. But how can I do this on Linux?

Thanks for any tips!

+4
source share
4 answers

I would probably start with named pipes

+1
source

You have many options:

  • Named Pipes
  • Msg Commands (msgget, msgsend);
  • Using TCP sockets;
  • Using UNIX domain sockets;
  • Using a third-party broker, for example DBus or ActiveMQ;

If this is for a standalone machine and for only one data stream, I would recommend option number 1.

+2
source

I used sockets and multicast for this purpose. This allows you to distribute processes between multiple computers on the same local network.

0
source

Source: https://habr.com/ru/post/1395443/


All Articles