Pipe() 系统调用
我正在系统课程中学习管道和外壳。我正在摆弄 strace
。我正在某个名为 dpipe 的程序上运行它。
在 strace
日志中,我看到以下内容:
pipe([3, 4])
pipe([5, 6])
这些整数代表什么?我认为管道基本上在 shell 中使用 |
将一个命令的输出路由到另一个命令的输入。所以它只会让我们的生活更轻松。在这种情况下,上面的数字数组代表什么?此外,如果 piping
只是在 shell 中使用,为什么还要有 C 系统调用呢?它是专为那些想要编写自己的 shell(让他们的生活更轻松)的人而设计的吗?
I am learning about piping and shell in a Systems class. I'm messing around with strace
. I am running it on some program called dpipe
.
In the strace
log, I see the following:
pipe([3, 4])
pipe([5, 6])
What do those integers represent? I under that piping is basically used in shell to route the output of one command, to the input of another using |
. So it just makes our lives easier. In this case, what do the array of numbers up there represent? Furthermore, if piping
is just used in shell, why is there C syscall for it? Is that made solely for those who want to write their own shell (to make their lives easier)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它们是
pipe(2,3p)
返回的文件描述符。有关更多详细信息,请参阅pipe(2)
手册页。They're the file descriptors returned by
pipe(2,3p)
. See thepipe(2)
man page for more details.Ignacio 正确地解释了方括号中的数字是
pipe()
系统调用。第一个是管道的读取端,第二个是管道的写入端。管道绝不只由 shell 使用,尽管这可能是最常见的使用它们的地方。然而,你把它搞反了; shell只能使用系统提供的系统调用,并且由于系统提供了pipe(),所以shell能够提供管道。如果没有操作系统以系统调用形式提供的支持,shell 就不可能提供管道表示法。所有系统调用都是为了使程序员能够向其客户(他们编写的软件的最终用户)提供服务。
Ignacio explained correctly that the numbers in square brackets are the two file descriptors returned by the
pipe()
system call. The first is the read end of the pipe, and the second is the write of the pipe.Pipes are by no means only used by the shell, though that is probably the most common place to use them. However, you have it backwards; the shell can only use the system calls provided by the system, and because the system provides
pipe()
, the shell is able to provide piping. Without the support from the o/s in the form of the system call, the shell would be unlikely to provide the pipe notation. All the system calls are there to make it possible for programmers to provide services to their customers (the end users of the software they write).它们是文件描述符。而且管道不仅仅用于外壳。管道可以由任何程序完成,它是 Unix 中进程交换信息的主要方式。对于 shell 来说这并不是什么特别的东西。 shell只是一个普通的进程,可以让用户轻松启动其他进程。
They are the file descriptors. And piping isn't just used in the shell. Piping can be done by any program and it's the primary way for processes to exchange information in Unix. It is not something special to a shell. A shell is just a normal process that makes it easy for the user to start other processes.