zoukankan      html  css  js  c++  java
  • pipe()

    NAME
    pipe, pipe2 - create pipe

    SYNOPSIS
    #include <unistd.h>

    int pipe(int pipefd[2]);

    #define _GNU_SOURCE /* See feature_test_macros(7) */
    #include <fcntl.h> /* Obtain O_* constant definitions */
    #include <unistd.h>

    int pipe2(int pipefd[2], int flags);

    DESCRIPTION
    pipe() creates a pipe, a unidirectional data channel that can be
    used for interprocess communication. The array pipefd is used to
    return two file descriptors referring to the ends of the pipe.
    pipefd[0] refers to the read end of the pipe. pipefd[1] refers to
    the write end of the pipe. Data written to the write end of the
    pipe is buffered by the kernel until it is read from the read end
    of the pipe. For further details, see pipe(7).

    If flags is 0, then pipe2() is the same as pipe(). The following
    values can be bitwise ORed in flags to obtain different behavior:

    O_NONBLOCK Set the O_NONBLOCK file status flag on the two new
    open file descriptions. Using this flag saves extra
    calls to fcntl(2) to achieve the same result.

    O_CLOEXEC Set the close-on-exec (FD_CLOEXEC) flag on the two new
    file descriptors. See the description of the same
    flag in open(2) for reasons why this may be useful.

    RETURN VALUE
    On success, zero is returned. On error, -1 is returned, and errno
    is set appropriately.

    先在父进程中创建管道,然后创建子进程,子进程复制了父进程管道文件的文件描述符,所以父进程和子进程各具有2个管道描述符,当在子进程中关闭读端, 这时关闭的是子进程中管道文件的读端,而父进程的读端没有关闭,这时子进程往写段写数据的时候,因管道读端未完全关闭,所以父进程不会收到SIGPIPE的信号。

  • 相关阅读:
    leetcode【dynamic】【0】
    VIM 常用指令
    《Java多线程编程核心技术》笔记
    log4j配置文件详解
    CSU 1803 2016(同余公式)2016年湖南省第十二届大学生计算机程序设计竞赛
    NYOJ 1233 差值(字符串排序+大数减法)
    HDU 5723 Abandoned country(最小生成树+DFS)
    POJ 1451 T9 字典树
    POJ 2965 The Pilots Brothers' refrigerator 状态压缩+广搜
    POJ 1753 Flip game状态压缩+广搜
  • 原文地址:https://www.cnblogs.com/feiling/p/3450792.html
Copyright © 2011-2022 走看看