The article directories

  • 1. Interprocess communication
    • (1) Overview
    • (2) Why do we need interprocess communication
    • (3) Eight methods of interprocess communication
      • 1. Anonymous pipeline communication
      • 2. Advanced pipeline communication
      • 3. Named pipe communication
      • 4. Message queue communication
      • 5. Semaphore communication
      • 6, signal
      • 7. Shared memory communication
      • Socket communication
    • (4) The connection and difference between unknown pipe and named pipe
      • 1, contact
      • 2, the difference between
    • (5) Explanation of each communication mode

1. Interprocess communication

(1) Overview

Here’s an explanation from Baidu Baike:

Interprocess communication (IPC) is a set of programming interfaces that allow programmers to coordinate different processes that run simultaneously in an operating system and communicate and exchange information with each other. This allows a program to handle many user requests at the same time. Even if only one user makes a request, it can cause multiple processes in an operating system to run and have to talk to each other. The IPC interface provides this possibility. Each IPC method has its own advantages and limitations, and it is not common for a single program to use all IPC methods.

Do not feel suddenly do not want to continue to see, it does not matter, please continue to see, as they did not see the above paragraph!

(2) Why do we need interprocess communication

There must be a reason for the concept of interprocess communication, or the ability to communicate, to exist. For example, the emergence of medicine is to cure disease, super notebook is to solve the problem of ordinary notebook heavy.

So what is the problem solved by the emergence of interprocess communication?

The answer:

To solve the problem of processes and data sharing between processes.

(3) Eight methods of interprocess communication

1. Anonymous pipeline communication

Pipe: A pipe is a half-duplex communication mode in which data flows only in one direction and can only be used between related processes. Process kinship usually refers to the parent-child process relationship.

2. Advanced pipeline communication

Advanced piping (POPEN) : Start another program as a new process in the current program process, it is a child of the current program, this method is called advanced piping.

3. Named pipe communication

Named pipe: Named pipe is also a half-duplex communication mode, but it allows communication between unrelated processes.

4. Message queue communication

Message queue: MESSAGE queues are linked lists of messages stored in the kernel and identified by message queue identifiers. The message queue overcomes the disadvantages of little signal transmission, pipe carrying only plain byte stream and limited buffer size.

5. Semaphore communication

Semophore: A semaphore is a counter that can be used to control access to a shared resource by multiple processes. It is often used as a locking mechanism to prevent other processes from accessing a shared resource while one process is accessing it. Therefore, it is mainly used as a means of synchronization between processes and between different threads within the same process.

6, signal

Sinal: Signals are complex forms of communication used to inform the receiving process that an event has occurred.

7. Shared memory communication

Shared memory: A shared memory map maps a segment of memory that can be accessed by other processes. This shared memory is created by one process but can be accessed by multiple processes. Shared memory is the fastest IPC method and is specifically designed for the low efficiency of other interprocess communication methods. It is often used in conjunction with other communication mechanisms, such as signal two, to achieve synchronization and communication between processes.

Socket communication

Socket: A socket is also an interprocess communication mechanism. Unlike other communication mechanisms, it can be used to communicate between processes of different machines.

(4) The connection and difference between unknown pipe and named pipe

1, contact

  1. Communication data exists only in memory buffered pages;
  2. Both are half duplex communication;

2, the difference between

  1. The nameless pipe is nameless, the named pipe is famous;
  2. An unnamed pipe can only be used for communication between parent and child processes or between sibling processes, while a named pipe can be used for communication between any two processes.
  3. Nameless pipes are invisible, that is, the inode structures of nameless pipes are not stored on disk, but are temporarily generated, while the inode nodes of named pipes are on disk.

(5) Explanation of each communication mode

… To be added.