Vamei Source: Http://www.cnblogs.com/vamei Welcome reprint, Please also keep this statement. Thank you!
Reference links
Http://www.cnblogs.com/vamei/archive/2012/09/14/2683756.html
Http://www.cnblogs.com/vamei/archive/2012/10/10/2715398.html
Text Flow principle
Everything is text, everything is text flow
When Unix executes a program, it automatically opens three streams, stdin, stdout, and stderr.
By default, stdin connects to the keyboard, stdout, and stderr connect to the screen.
Although all open, but not all must use.
Text Flow Example
Keystrokes ("ls\n") of the stdin, flow into the command line (command line is also a program),
The command line calls/bin/ls to get the output stream ("A.txt"),
The output stream flows to the screen.
redirect
Directing custom content to stdout, Echo
REDIRECT stdout, using ' > ' or ' >> '
redirect stdin, using ' < '
REDIRECT stderr, using ' 2> ' or ' 2>> '
REDIRECT stdout and stderr using ' >& '
redirect Example
Cat < a.txt > B.txt # Copy the contents of A.txt to the B.txt
Pipeline
To direct the output of one command to the input of another command
Use pipelines to connect multiple processes together, allowing each process to collaborate to achieve complex functionality.
Pipeline understanding
A pipeline is a buffer that is managed by the kernel, which is the equivalent of a small note that we put into memory.
One end of the pipeline connects the input of a process, and the other end connects to the input of another process.
The pipe does not need to be large, and he is designed as a data structure for circular data so that it can be recycled.
If there is no information in the pipeline, the process read from the pipeline waits.
When the pipeline is full of information, the process of trying to put information waits.
The pipe automatically disappears when all two processes are terminated.
Piping principle
The pipeline is built using the fork mechanism so that two processes can be connected to the same pipe.
At the beginning, the input and input of the pipeline are connected to the same process Process1,
When you fork the copy process, both connections are copied to the new process PROCESS2.
Subsequently, two processes each shut down one of their unwanted connections, forming a pipe that connects two processes
Fifo
http://blog.csdn.net/lianghe_work/article/details/47722175
Because pipelines are built on the fork mechanism, pipelines can only be applied between parent-child processes, or between two child processes that have the same ancestor. To solve this problem, Linux provides a FIFO way to establish a connection.
FIFO is also called named pipe
FIFO is a special type of file that has a corresponding path in the file system, but it is managed by the kernel.
When a process opens the file in a read manner, and another process opens the file in a written manner, the kernel creates a pipeline between the two processes.
FIFO is a file in the file system, but his content is in memory.
FIFO files still exist in the file system after the process is exited with FIFO
FIFO has a name, unrelated processes can communicate by opening a named pipe
Linux system Knowledge-text flow & pipeline