There are two programs on one computer. Is it possible to do so:

  1. Program 1 takes out pointers to 2 of its functions and sends it to another program on a UNIX socket.
  2. Program 2 receives these pointers and, using a socket, it passes 1 pointer to its function.
  3. The socket is destroyed and the programs are pinged by exchanging the "Hello program!" together.
  4. Profit!

Is it possible to do this? The main question: how to perform the function on the pointer and how to pass parameters to it?

  • Only if both programs are in the same address space. And to execute is not a problem - you cast to the necessary type, and call - Vladimir Gamalyan
  • one
    It is possible to do this if you load the compiled portable function code into shared memory available to both programs. But I think that for you it will be an impossible task, and I don’t see the point in such somersaults. PS: two different processes are usually located in different address spaces that are incompatible with each other. - sergw
  • 9
    In how simple it is, throw a function pointer over a socket. And the guys who wrote CORBA / SOAP / DCOM did not know. - VladD
  • ru.wikipedia.org/wiki/… - aleksandr barakin
  • @VladD, but would dos work? Or not? - Qwertiy ♦

2 answers 2

You can try to use shared memory, in fact, it serves for this purpose, to connect two programs with one memory. On Habré even the article is

  • one
    Doesn't work the same? - Qwertiy ♦
  • @Qwertiy why won't it work? - Pavel Mayorov
  • @PavelMayorov, in order to work, it is necessary that everything that this function calls will also be in shared memory. Or am I wrong? - Qwertiy ♦
  • @Qwertiy well, it's obvious :) - Pavel Mayorov
  • @PavelMayorov, but it’s unrealizable, right? - Qwertiy ♦

This can not be done, since each application has its own address space. But you can organize a shared memory in which the first program writes DATA, and the second program reads them and somehow processes OWN functions, and the same in the opposite direction. That is, we must look towards changing the logic of the program.