2016-03-31 Summary

Source: Internet
Author: User

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

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.