The main communication methods of processes in the Linux system are as follows:
Process communication method on the same host
Process communication mode between network hosts
Their characteristics:
- Pipe (PIPE): Pipe is a half-duplex communication method. Data can only flow in one direction, and it can only be used between processes with kinship (parent and child processes). In addition, the pipe transmits an unformatted byte stream, and the size of the pipe buffer is limited (the pipe buffer exists in memory, and when the pipe is created, a page size is allocated for the buffer).
- Well-known pipe (FIFO): The well-known pipe is also a half-duplex communication method, but it allows communication between unrelated processes.
- Signal (Signal): Signal is a more complex communication method used to notify the receiving process that an event has occurred.
- Semaphore: Semaphore is a counter that can be used to control access to shared resources by multiple processes. It is often used as a locking mechanism to prevent other processes from accessing shared resources when a process is accessing the resource. Therefore, it is mainly used as a means of synchronization between processes and between different threads in the same process.
- Message Queue (Message Queue): The message queue is a linked list of messages, stored in the kernel and identified by the message queue identifier. The message queue overcomes the shortcomings of less signal transmission information, the pipeline can only carry unformatted byte streams, and the limited buffer size.
- Shared Memory (Shared Memory): Shared memory is to map a section 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. It is specifically designed for the low efficiency of other inter-process communication methods. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and communication between processes.
- Socket: Socket is also an inter-process communication mechanism. Different from other communication mechanisms, it can be used for process communication between different hosts.
The thread communication methods in the Linux system are mainly as follows:
*
*
*
The purpose of communication between threads is mainly for thread synchronization. Therefore, threads do not have a communication mechanism for data exchange as in process communication.