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

发布于 2024-10-25 05:25:41 字数 412 浏览 4 评论 0原文

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

pipe() 创建一个管道,一个可用于进程间通信的单向数据通道。”

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

pipe()系统调用创建一个管道,它是一个允许双向数据流的对象,并分配一对文件描述符。”

一个是单向的,另一个是双向的。我希望这不是一个愚蠢的问题,但是哪个方法是这样做的标准方法吗?

为了明确我的意图,我在考试中失去了一些分数,因为我相信 pipeline() 是一种方法,并且正在寻找一些弹药来恢复任何分数;p

In Linux (2.6.35-22-generic), man pipe states that

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

In FreeBSD (6.3-RELEASE-p5), man pipe states that

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

One is unidirectional, the other is bidirectional. I hope this isn't a silly question, but which method is the standard way of doing this? Are they both POSIX compliant?

To make my intentions clear, I lost some points on an exam for believing pipe() was one way and am looking for some ammo to get any points back ;p

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我一向站在原地 2024-11-01 05:25:41

我一开始是作为对 Greg 答案的评论开始的,但我发现它更接近地回答了您的具体问题:

pipe()s POSIX 标准中的文档 明确指出所讨论的行为是“未指定的”——即 pipe()< /code> 并不要求是双向的,但并不禁止。 Linux 是单向的,FreeBSD 是双向的。两者都是兼容的,其中一种只是实现了不需要的额外行为(但不会破坏为在兼容系统上运行而构建的应用程序)。

可以将数据写入文件
描述符 fildes[1] 并从
文件描述符fildes[0]。继续阅读
文件描述符 fildes[0] 应
访问写入文件的数据
描述符 fildes[1] 上
先进先出的基础上。这是
未指定 fildes[0] 是否也是
是否开放写入以及是否 fildes[1]
也可供阅读。

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

I started this as a comment on Greg's answer at first, but it occurs to me that it more closely answers your specific question:

pipe()s documentation in the POSIX standard explicitly states that the behavior in question is "unspecified" -- that is, pipe() is not required to be bidirectional, though it's not forbidden. Linux's is unidirectional, FreeBSD's is bidirectional. Both are compliant, one just implements additional behavior that is not required (but doesn't break apps built to work on compliant systems).

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.

I wouldn't count on getting the points back (though you should). Professors have a tendency to ignore the real world in favor of whatever they've decided is correct.

凉月流沐 2024-11-01 05:25:41

FreeBSD 的 pipe 手册页在这一点上非常清楚:

这种管道实现的双向性质无法移植到旧系统,因此建议在单向使用管道时使用以传统方式使用端点的约定。

The FreeBSD man page for pipe is pretty clear on this point:

The bidirectional nature of this implementation of pipes is not portable to older systems, so it is recommended to use the convention for using the endpoints in the traditional manner when using a pipe in one direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文