Answer the question
In order to leave comments, you need to log in
How is interprocess communication done in C++?
Hello, habrovtsy. I recently finished reading Stephen Prat's book on C++ programming. After it, one open question remained: how is interprocessor communication carried out in C ++, that is, how can a function be called from a "foreign" process? Heard something about native functions, is it relevant to the topic? Thanks in advance for your replies.
Answer the question
In order to leave comments, you need to log in
Not in C++. Any interaction with the external (for the program) world is a privilege of the OS kernel. The STL provides a very limited set of wrappers for the system API, and communication between processes is not included in this set. The traditional way to communicate is Pipe and Socket, but they just transfer byte arrays. And if you need to build an RPC, then you need to serialize the parameters and send them in this form. And one way or another, you will have to write these wrappers yourself, since there is no full-fledged RTTI in C ++.
As in any other language, pipes, sockets, signals, shared memory, events. Essentially you need to set up the transmitter and receiver and wrap it all in code.
Calling a function from a foreign process is not exactly interprocessor communication. We have already written above about sockets and so on, but this is all for data transfer, but to call the function directly, there are some doubts. Still, this is a completely different address space and I'm not sure that you can get the address of the function. If this is possible, then it is enough to cast the pointer to the desired type, correct the stack, if necessary, and call it. This works in one process (for example, if you "steal" the function of the main application from a dll), but I'm not sure between processes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question