ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

为什么管道可以使用的进程之间的关系在Linux API和Bash中是不同的

2019-08-28 11:01:35  阅读:141  来源: 互联网

标签:c-3 bash linux shell pipe


我想知道为什么管道可以使用的进程之间的关系在Linux API和Bash中是不同的.

>在Linux API中,未命名的管道(pipe())只能在父子进程之间使用.
>在Bash中,可以在两个进程之间使用管道,这两个进程将shell进程作为其共同父进程.

Bash中的管道是否根据Linux API中未命名的管道实现?谢谢.

来自APUE 3ed:

15.2 Pipes

Pipes are the oldest form of UNIX System IPC and are provided by all
UNIX systems. Pipes have two limitations.

  1. Historically, they have been half duplex (i.e., data flows in only one direction). Some systems now provide full-duplex pipes, but for
    maximum portability, we should never assume that this is the case.

  2. Pipes can be used only between processes that have a common ancestor. Normally, a pipe is created by a process, that
    process calls fork, and the pipe is used between the parent and the
    child.

We’ll see that FIFOs (Section 15.5) get around the
second limitation, and that UNIX domain sockets (Section 17.2) get
around both limitations.

15.5 FIFOs

FIFOs are sometimes called named pipes. Unnamed pipes can be used
only between related processes when a common ancestor has created the
pipe.
With FIFOs, however, unrelated processes can exchange data.

解决方法:

  • In Linux API, unnamed pipes (pipe()) can be used only between parent-child processes.

不对.任何具有文件描述符的进程都可以使用它们:父进程,任何子进程,任何具有received them via domain sockets的进程等.

bash中的管道只是儿童与儿童交流的特定情况.

标签:c-3,bash,linux,shell,pipe
来源: https://codeday.me/bug/20190828/1750807.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有