Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communication between Linux programs

Tags:

c

unix

posix

ipc

how would I implement communication between Linux programs written in C? Specifically, I want the following:

My program can run in multiple instances. Upon startup, I want that my program detects all other instances of my program that are already running and then it should be able to send a text string to them. On the other hand, I also want that the instances that are already running get notified that a new instance has been started and they should also be able to send a text string to the new instance.

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

Thanks for any hints!

like image 938
Andreas Avatar asked Feb 08 '12 16:02

Andreas


People also ask

How do I communicate between two applications in Linux?

shared memory and message queues can be used to exchange information between processes. The difference is in how they are used. both have some advantage and disadvantage. it's an area of storage that can be read and written by more than one process.

How to processes communicate Linux?

Processes communicate with each other and with the kernel to coordinate their activities. Linux supports a number of Inter-Process Communication (IPC) mechanisms. Signals and pipes are two of them but Linux also supports the System V IPC mechanisms named after the Unix TM release in which they first appeared.

How do programs communicate with each other?

Applications can communicate using an Application Programming Interface (API). When writing a program, the developer can choose to expose certain functions to allow other programs to interact with them.


1 Answers

You have a lot of options:

  • Named pipes;
  • Msg commands (msgget, msgsend);
  • Using TCP sockets;
  • Using UNIX domain sockets;
  • Using a third party broker, like DBus or ActiveMQ;

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

like image 60
Bruno Soares Avatar answered Sep 30 '22 09:09

Bruno Soares