Inter-process communication of operating system process


This article sorts out the communication method between operating system processes from the perspective of operating system.

Process communication


Process communication refers to the exchange of information between processes.
A process is the unit that the operating system allocates resources. Each process has its own independent memory address space; but in order to ensure the security of the operating system, a process cannot directly access the address space of another process, so the operating system provides some methods to let Information exchange between processes is inter-process communication.

The methods provided by the operating system are: shared storage, pipe communication, and message passing.

Shared storage


The operating system allocates a shared space for two processes, and the two processes communicate by operating the shared space.

  • Must be mutually exclusive The
    access of the two processes to the shared space must be mutually exclusive, or mutual exclusion is achieved through tools provided by the operating system, such as P, V operations

  • Shared storage is divided into two types, sharing based on data structure and sharing based on storage area

    • Data structure-based sharing
      means that only one fixed data structure can be stored in the shared space. This sharing method is slow and has many restrictions. It is a low-level communication method.
    • Storage area-based sharing
      A shared storage area is drawn in the memory, and the form and storage location of the data are controlled by the process; this sharing method is faster and is an advanced communication method.

Pipeline communication


A pipe refers to a shared file used to connect to read and write processes, also called a pipe file. In fact, it opens up a fixed-size buffer in the memory.
The buffer size is generally the same as the size of a memory page, which is 4kb in a Linux system.

  • Pipe communication can only use half-duplex communication.
    If you want to achieve two-way simultaneous communication, you need to set up two pipes.

  • Mutually exclusive access channels for each process

  • The data is written into the pipe in the form of a character stream: if it is not full, it is not allowed to read; if it is not empty, it is not allowed to write.
    When the pipe is full, the write() system call of the writing process will be blocked and wait The reading process takes the data away;
    when the reading process takes all the data away, the pipe becomes empty, and the read() system call of the reading process will be blocked at this time;

  • Once the data is read, it is discarded from the pipeline.
    This means that there can only be one read process at most, otherwise there may be data read errors.



Message passing refers to the way that the data exchange between processes is based on formatted messages as a unit, through the two primitives of sending and receiving messages provided by the operating system.

  • A formatted message
    generally consists of a message header and a message body; the
    message header includes: formatted messages such as sending process ID, receiving process ID, message type, and message length.

There are two types of messaging: direct communication and indirect communication

  • Direct communication method
    Process 1 sends the formatted message to the target process 2 through the sending primitive, and the message is directly linked to the end of the message buffer queue of the receiving process. Process 2 reads the values ​​in the buffer queue sequentially through the receiving primitive.

  • Indirect communication means
    that the message is sent to the intermediate entity (mailbox) first, so it also becomes the mailbox communication method.
    The system will manage a mailbox for each communication process. There are various messages that are being communicated between different processes in the mailbox. Because the message header contains the mailbox of each process, there is no need to worry about getting the wrong one.
    Process 1 sends the message to the mailbox by sending primitives, and process 2 reads the message by receiving primitives.

Guess you like