The efficiency is not very high Ah, record the following two comparison pits place:
1. The pipeline is actually stored in memory, whether it is a named pipe or a nameless pipe, placed in the kernel's buffer.
The pipeline has the following two restrictions:
1) The pipe capacity is limited and cannot be changed, so it is not appropriate to use the pipeline for large-scale data communication, under Linux this limit is 64k,65535 bytes.
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <signal.h> int main (int argc, char *argv[]) { int Pipefd[2];char buf[100000] = {0}; if (pipe (PIPEFD) = =-1) {fprintf (stderr, "pipe error"); return 1;} int ret; int count = 0; int flags = FCNTL (pipefd[0], F_GETFL); Fcntl (Pipefd[1], F_SETFL, Flags | O_nonblock); Set to non-blocking while (1) { ret = write (pipefd[1], buf, sizeof (BUF)); if (ret = =-1) { printf ("Write Error:%s\n", Strerror (errno)) ; break; } count++; } printf ("Count =%d\n", count); Pipe capacity return 0;}
2) The pipe has a buffer limit. That is, PIPE_BUF, which is the maximum length of write Atomic writes, as follows:
The write FD is in blocking mode:
Writes the character n <= pipe_buf, if the PIPE has enough space, the atomicity is written. If there is not enough space left, block until you can write all.
Writes the characters n > pipe_buf, writes are not atomic, may intersect with other processes, and is blocked until all n characters are written successfully.
The Write FD is non-blocking:
Writes the character n <= pipe_buf, if there is not enough space, will return a failure, error code Eagin
Writes the character n > pipe_buf, if there is not enough space, the character that may write any one of the values in 1-n, the return value needs to be retrieved from the line judgment.
2. Today the standard input and standard output are redirected to the file, and then want to use Epoll to wait for the file read and write events, but in the epoll_ctl time found that the failure: Epoll_ctl:operation not permitted. Find out only to discover: regular file (that is, ordinary files) is not supported Epoll/select operation, because they are at any time readable/write state.
2016-03-31 Summary