First, the pipeline definition
A pipeline is a mechanism for one-way communication between two processes. Pipelines are also referred to as half-duplex pipes because of the unidirectional nature of the pipeline passing data. This feature of the pipeline determines the limitations of the use of the device. The pipeline is one of the original UNIX IPC forms supported by Linux and has the following features:
Data can flow from one process to another (one read pipeline, one write pipeline), or two pipelines if you want to do duplex communication.
Pipelines can only be used for parent-child processes or sibling interprocess communication. , which means that pipelines can only be used for inter-process communication with affinity.
Note : reading data from a pipe is a one-time operation, once the data is read, it is discarded from the pipeline, freeing up space to write more data.
Second, the pipeline command
Command1 | Command2 | Command3
The operator is: "|", it can only handle the correct output information through the preceding instruction, and has no direct processing ability to the error information information. Then, pass to the next command as the standard input.
Output description of the Administration command:
"Instruction 1" is correctly output, as the input of "instruction 2" and then "instruction 2" output as the input of "instruction 3", "instruction 3" output will be displayed directly on the screen.
The correct output of "instruction 1" and "Directive 2" after the pipe is not displayed on the screen
"Reminder Note":
1. The pipeline command only handles the correct output of the previous command, and does not process the error output;
2. Pipe command to the right, you must be able to receive the standard input stream command before the line;
Third, Pipeline application
1. read out the contents of the Logcat.log file, and send it through the pipeline to grep as the input content
Cat Logcat.log | Grep–n ' Activitmanager '
#2. read out the contents of the Logcat.log file, pass the pipeline to grep as input, filter the line containing ' Displayed ', and then forward the output as input to the next grep
Cat Logcat.log | Grep–n ' Displayed ' | Grep??
#3. Read the contents of the Logcat.log and Wirelessqa.log files, the contents of the error will be printed on the screen and the correct channel will be passed to grep
#4. read out the contents of the Logcat.log and Wirelessqa.log files, the contents of the error are redirected to/dev/null, and the correct channel is passed to grep
#5. Readout Logcat.log is passed to LS through the pipeline, because LS does not support standard input, so the previously read-in data is lost.
How the Linux command pipeline works and how to use it