Are the callback and interprocess communication functions the same?

A few days ago in an interview I was asked one question:

Are function callback in C and interprocess communication are same? 

I was a bit neutral in this matter. Because I was in a dilemma. In IPC, we associate a process with a process at the end, if we see that a process is nothing more than a function. Here, one function calls another function. In the function callback, we again use the function pointer , that one function calls another function with an address. So I just wanted to know, although they are not quite the same, so what's the difference?

+6
source share
2 answers

No, not at all.

The callback function passes the address (or some other identifier) ​​of the function to another function so that for some reason it can call back.

A classic example is the C qsort standard library. You pass a pointer to an array (and its dimensions) along with a comparison function. The qsort function then uses this comparison function (callback) to decide which of the two items in the list is greater so that it can arrange them.

IPC, on the other hand, is a means for processes to interact with each other, such as shared memory, pipes, semaphores, etc.

Some IPC mechanisms may use callbacks, but this is by no means necessary. For example, sockets do not use callbacks; they simply allow the user to call read and write .

Similarly with shared memory, you join the memory blocks and simply access them in the same way as the β€œnormal” memory, just that the effects are felt in all processes connected to this memory.

One who uses callbacks is ONC RPC (or Sun RPC). It starts a server that waits for client calls over the network and passes them to a pre-configured client function. More information can be found here .

But even then I would not dare to call it a callback, since it is really configured at compile time. Correct callbacks are usually executed at run time.

+10
source

The function callback function means that the caller and callee are in the same thread. IPC is in different processes. a process consists of one or more threads. Ergo, callbacks are not IPC.

+6
source

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


All Articles