The interaction of the two c / C ++ programs

In this I do not understand at all. Maybe this is too wide for the stack, but here it is:

Suppose I have two programs (written in C / C ++) running simultaneously, for example A and B, with different PIDs.

What are the options to do, then interact with each other. For example, how I transmit information from one to another, for example, if you have the opportunity to wait for a signal from another and respond accordingly.

I know MPI, but MPI usually works for programs that are compiled using the same source (therefore, it is more suitable for parallel computing than just interaction from completely different programs built to interact with each other).

thanks

+4
source share
3 answers

You should keep an eye on "IPC" (interprocess communication). There are several types:

  • pipes
  • signals
  • Common memory
  • message queues
  • semaphores
  • files (suggested by @JonathanLeffler: -)
  • RPC (suggested by @sftrabbit)
    This is usually more client / server oriented.
    • CORBA
    • D-bus
+5
source

You use one of the many mechanisms of interaction between processes, such as channels (one application writes bytes to a channel, another reads from it. Imagine stdin / stdout.) Or shared memory (the memory area is mapped into both programs by virtual address space and they can be exchanged data through it).

+2
source

The same source does not matter - as soon as your programs are compiled, the system does not know and does not care about where they came from.

There are different ways of communicating between them, depending on how much data, how fast, one way or bidirectional, predictive speed, etc. etc....

The simplest thing is simply to use the network - note that if you are on the same machine, the network stack automatically uses some higher performance system to actually send data (i.e. shared memory)

0
source

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


All Articles