在 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/