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, );