1. Use FIFO to copy the output stream
Pipelines can only be used for linear connections between processes, while FIFO has a name, so they can be used for non-linear connections.
Use FIFO and Unix systemsProgramTee, you can achieve the process without using temporary files. (The Tee program copies its standard input to its standard output and the name file contained in its command line .)
Mkfifo ikeo1
Prog3 < FIFO &
Prog1 < Infile | Tee 0000o1 | Prog2
Note:
- First, create a FIFO
- Then, start prog3 in the background, which reads data from the FIFO.
- Then, start prog1 and use tee to send its output to FIFO (prog3) and prog2
2. the C/S process uses FIFO for communication
If a server process is related to many client processes, each client process can write its requests to a well-known FIFO process created by the server process. because there are multiple write processes for this FIFO, the length of the request sent by the client process to the server process is smaller than pipe_buf bytes. in this way, the customer can avoid the interruption between multiple writes.
In this similar c/s Process Communication, the question is: how does a server process send the answer back to each customer process?
A single FIFO cannot be used, because the server process will send a response to the request of each customer process, but the requester cannot know when to read the response.
The solution to this problem is:
- Each client process contains its process ID in its request.
- The server process then creates a FIFO for each customer process. The path name used is based on the process ID of the customer process. for example,/tmp/serv1.xxxx, where XXXX is replaced with the ID of the customer process.
- The server process must capture the sigpipe signal, because the client process may terminate if it does not read the response after sending a request, so a dedicated FIFO is left for the client process that only writes the process but does not read the process.
However, there are still some shortcomings in this arrangement, that is, after the customer's process crashes, the FIFO records created by the server for it will be left in the file system.