linux - POSIX:FreeBSD 与 Linux 中的管道系统调用

标签 linux posix pipe freebsd

在 Linux (2.6.35-22-generic) 中,man pipe 指出

pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication."

在 FreeBSD (6.3-RELEASE-p5) 中,man pipe 指出

The pipe() system call creates a pipe, which is an object allowing bidirectional data flow, and allocates a pair of file descriptors."

一个是单向的,一个是双向的。我希望这不是一个愚蠢的问题,但哪种方法是执行此操作的标准方法?它们都符合 POSIX 标准吗?

为了明确我的意图,我在一次考试中因为相信 pipe() 是一种方式而丢了一些分数,我正在寻找一些弹药来取回任何分数;p

最佳答案

起初我是作为对 Greg 的回答的评论开始的,但我发现它更接近于回答您的具体问题:

pipe()s documentation in the POSIX standard明确指出所讨论的行为是“未指定的”——也就是说,pipe() 不需要是双向的,尽管它不是被禁止的。 Linux 是单向的,FreeBSD 是双向的。两者都是合规的,一个只是实现了不需要的额外行为(但不会破坏为在合规系统上运行而构建的应用程序)。

Data can be written to the file descriptor fildes[1] and read from the file descriptor fildes[0]. A read on the file descriptor fildes[0] shall access data written to the file descriptor fildes[1] on a first-in-first-out basis. It is unspecified whether fildes[0] is also open for writing and whether fildes[1] is also open for reading.

我不会指望拿回积分(尽管你应该)。教授们倾向于忽视现实世界,而倾向于他们认为正确的任何事情。

关于linux - POSIX:FreeBSD 与 Linux 中的管道系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5385534/

相关文章:

c - 在 Linux 上获取文件选择器的简单方法

php - 无法登录 PHP 应用程序

c - 有什么方法可以将内存位置更改为 C 中的共享内存?

linux - 如果第二列中的数据相同,则第一列的 Bash 添加

c - POSIX:您如何确定您自己的进程的文件镜像以便您可以执行自己?

c++ - 为什么tail -f 取不到数据?

javascript - Node.js 通过管道发布请求并获取响应

linux - Unix : how does a "./process | sort" work?

python - 通过管道 iostat -d 1 到 python sys.stdin

php - 我正在经历一个 php 后台进程问题