How is interprocess communication (IPC) implemented?
1, pipe (pipe)
Can be used both in the program and in the shell.
Pipeline is a half-duplex communication method, and data can only flow in one direction.
The problem with pipes is that they don't have names and can only be used between processes that have affinity (between father and child processes).
Extension:
The pipeline is created by the pipe function and provides a one-way data stream. When we need a two-way data stream, we have to create two pipes, one for each direction. This is the principle of implementation of a full-duplex pipe: it consists of two half-duplex pipes.
2, named pipe (named pipe): FIFO
Named pipes are also half-duplex communication methods. Provide one-way data flow.
Overcoming the limitation of the pipe without name, thus allowing unrelated process-to-process communication, solving the above problems of the pipeline.
Extension:
Both the pipe and the FIFO are accessed using the usual read and write functions.
The FIFO is created by the mkfifo function. Unlike FIFOs, each FIFO has a pathname associated with it, allowing unrelated processes to access the same FIFO.
The real advantage of FIFO is that the server can be a long-running process (such as a daemon) and can be unrelated to its customers.
3, semaphore (semophore)
Mainly as a means of synchronization between processes and between different threads within the same process.
Inter-process communication handles the mechanism of synchronous mutual exclusion. A semaphore is a counter that can be used to control access to shared resources by multiple processes. It is often used as a lock mechanism to prevent a process from accessing a shared resource while other processes are also accessing it.
4, the signal (sinal)
Is a way to handle asynchronous events.
A signal is a more complex form of communication used to notify the receiving process that an event has occurred. In addition to being used for processes, you can also send a signal to the process itself.
Signals and semaphores are different. Although they can be used to achieve synchronization and mutual exclusion, the former is performed using a signal processor, and the latter is implemented using P and V operations.
5, message queue (message queue)
The message queue is a linked list of messages, including the Posix message queue systemV message queue.
A process with sufficient permissions can add messages to the queue, and processes with sufficient read permissions can read messages from the queue.
Message Queuing overcomes the shortcomings of signal bearer information, the pipeline can only carry unformatted byte streams and the buffer size is limited.
Extension:
Message Queuing has persistence with the kernel, which is different from pipes and FIFOs. When the last shutdown of a pipe or FIFO occurs, data still on that pipe or FIFO will be discarded.
Two message queues: no real descriptors are used, so using select or poll on the message queue is difficult. Two message queues: Before a process writes a message to a queue, no other process is required to wait for the arrival of the message on the queue.
One of the problems with SystemV message queues is that they cannot tell a process when a message is placed in a queue, that is, it cannot snoop a message. The Posix message queue allows asynchronous event notifications to tell when a message has been placed in an empty message queue.
The main feature of the Posix message queue miss is the ability to read out the specified priority messages from the queue.
When using pipes and FIFOs, two IPC channels are required to exchange data in both directions. A single queue is sufficient when using Message Queuing, and the type of each message identifies whether the message is from the client to the server or from the server to the client.
The linked list header of the Posix Message Queue message list contains two attributes of the current queue: the maximum number of messages allowed in the queue and the maximum size of each message.
Two restrictions on the Posix Message Queue message queue: The maximum number of open message queues a process can have at the same time; the maximum priority of any message.
6, shared memory (shared memory)
Is the same piece of memory space created by one process but accessible by multiple processes. It is the fastest form of available IPC (because a single copy of the data in the shared memory area is available to all threads or processes sharing that memory).
It is designed to be less efficient at operating other communication mechanisms. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and communication between processes.
The problem with the general IPC form (pipeline, FIFO, message queue) is that the two processes exchange information, which must be passed through the kernel. When sharing memory between processes, exchanging data no longer involves the kernel. These processes must coordinate or synchronize the use of this shared memory area.
Use shared memory for client-server file copy: This shared memory area exists in both the client and server address spaces.
The data only needs to be copied twice: once from the input file to the shared memory area, and once from the shared memory area to the output file.
However, other IPC forms (pipe, FIFO, message queue) require four copies:
In addition, child processes that are forked by default do not share memory regions with their parent processes by default. ! ! !
7, socket (Socket)
A more general interprocess communication mechanism that can be used for interprocess communication between different machines.
8, remote procedure call: RPC
Silicon TVS / TSS:
Diode TVS (Transient Voltage Suppressor), also known as Transient suppression diodes, is widely used a new type of high efficient circuit protection device, it has a fast response time (the nanosecond) and high surge absorbing ability.When it ends of stand moments of high energy shock, TVS can bring the two ends at high rate from high impedance to a low impedance between impedance values, to absorb a large current moment, put it at both ends of the voltage restraint on a predetermined value, thus protecting the back of the circuit components are not affected by the impact of the transient high pressure spikes.
Silicon TVS Transient Voltage Suppresso,Silicon TSS Transient Voltage Suppresso
YANGZHOU POSITIONING TECH CO., LTD. , https://www.cnpositioning.com