What is a pipeline in linux?

青灯夜游
青灯夜游Original
2019-12-25 18:27:578457browse

What is a pipeline in linux?

Pipeline is an inter-process communication mechanism inherited by Linux from Unix. It is an important communication mechanism in the early days of Unix. The idea is to create a shared file in memory so that both communicating parties can use this shared file to transfer information. Since this method has the characteristics of one-way data transmission, this shared file used to transmit messages is called a "pipeline".

In the specific implementation of pipes, there are "anonymous pipes" and "named pipes" depending on whether the files used for communication have names.

The difference between pipes and shared memory

At first glance, it seems that there is not much difference between pipes and shared memory. Here is an introduction to the difference between the two:

● The pipeline requires four data copies between the kernel and user space: copy data from buf in user space to the kernel -> kernel copies data to memory -> memory to kernel -> ; Kernel to user space buf. Shared memory only copies data twice: user space to memory -> memory to user space.

● The pipeline is implemented using a circular queue, and data can be continuously transmitted without any size limit. The size of data transferred in shared memory is fixed each time;

● Shared memory can randomly access any location of the mapped file, while pipes can only read and write sequentially;

● Pipes can complete data processing independently Delivery and notification mechanisms, shared memory requires the use of other communication methods for message delivery.

In other words, the biggest difference between the two is: Shared memory area is the fastest available IPC form. Once such a memory area is mapped to the address space of the process that shares it, the data between these processes Pass, you no longer need to execute any system calls into the kernel to pass each other's data, saving time.

Recommended related articles and tutorials: linux tutorial

The above is the detailed content of What is a pipeline in linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn