Linux IPC: Understanding Interprocess Communication

First, the understanding of inter-process communication

What is interprocess communication?

  Inter-process communication is the transfer of information (data) between processes.

Why do processes need to communicate?

  When writing code, in order to reduce the complexity of the code, we usually encapsulate some frequently used code into functions. When using functions, some data will also be passed between functions through return values.

  Then in a large project, a project is usually divided into multiple programs, and after multiple programs run, multiple processes will be generated. Data needs to be passed between functions, and data also needs to be passed between processes. The passed data makes the project run normally, but data cannot be directly passed between processes.

Why can't data be passed directly between processes?

  Here we have to recall the virtual memory, each process has its own unique virtual memory. If process A wants to pass the address of variable M to process B, if the address of M is directly given to process B, what process B gets is actually a virtual address, but using this address to find data in process B’s own virtual space cannot be found arrived.

Two, common inter-process communication methods

  Because data cannot be directly transmitted between processes, the operating system provides some inter-process communication methods so that data can be transmitted between processes.

  Commonly used inter-process communication methods are: pipes, shared memory, message queues, and semaphores . Different communication methods have different characteristics and are used to deal with different scenarios.

  The essence of these inter-process communication methods is a common access space , and processes that need to communicate with each other can pass or receive data by accessing this common space.

おすすめ

転載: blog.csdn.net/weixin_57761086/article/details/128524118
IPC