[Reading Notes] pipelines and FIFO

Source: Internet
Author: User

MPs queue

Provides a single (one-way) data stream, which can provide communication means between two different processes.

#include <unistd.h>     pipe( fd[]);

Returns two file descriptors, fd [0] () and fd [1] ().

Communication between pipelines is usually completed using the read and write Functions.

 

Typical pipeline usage:

First, the parent process creates an pipeline and then calls fork to derive a copy of itself.

Next, the parent process closes the read end of the pipeline, and the child process closes the write segment of the pipeline.

In this way, a one-way data flow is provided between parent and child processes.

 

Dual-pipeline:

When a two-way data flow is required, we must create two pipelines, one in each direction.

    pipe1[], pipe2[( (childpid = Fork()) ==);

 

 

 

 

FIFO

It refers to the first in, first out, which is a one-way data stream.

Different from pipelines, each FIFO has a path name associated with it, which allows unrelated processes to access the same FIFO, and thus is also called "famous Pipeline ". ()

#include <sys/types.h><sys/stat.h> mkfifo( * pathname, mode_t mode);

Pathname is a path name and also the name of the FIFO.

Mode indicates the File Permission bit.

S_IRUSR

S_IWUSR

User (owner) read

User (owner) Write

S_IRGRP

S_IWGRP

(Owner) group member read

(Owner) group member write

S_IROTH

S_IWOTH

Read by other members

Write by other members

The constant value oo_mode is defined in unpipc. h:

 FIFE_MODE ( S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH )

 

Unlike pipelines:

    

 FIFO1 "/tmp/fifo.1" FIFO2 "/tmp/fifo.2"( (mkfifo(FIFO1, FILE_MODE) < ) && (errno !=( (mkfifo(FIFO2, FILE_MODE) < ) && (errno !=( (childpid = Fork()) === Open(FIFO1, O_RDONLY, = Open(FIFO2, O_WRONLY,     = Open(FIFO1, O_WRONLY, = Open(FIFO2, O_RDONLY, );

 

 

 

 

 

Related Article

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.