Linux inter-process communication: FIFO (2)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.