C++如何创建/使用管子和叉子?

发布于 2025-01-01 02:34:05 字数 132 浏览 4 评论 0原文

我需要学习如何创建pipe并使用fork,以及如何写入pipe读取,在 VC++ 2010 中。

有关于如何做到这一点的教程吗?

I need to learn how to create a pipe and use fork, and also how to write to a pipe and read, in VC++ 2010.

Are there any tutorials on how to do that?

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

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

发布评论

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

评论(1

只为一人 2025-01-08 02:34:05

这个问题已经在此处得到了详细解答。
逐字引用同一答案

管道是一种进程间通信的机制。一个进程写入管道的数据可以由另一进程读取。创建管道的原语是管道函数。这将创建管道的读取端和写入端。对于单个进程来说,使用管道与自身对话并不是很有用。在典型使用中,进程在派生一个或多个子进程之前创建一个管道。然后,管道用于父进程或子进程之间或两个兄弟进程之间的通信。在所有操作系统 shell 中都可以看到这种通信的常见示例。当您在 shell 中键入命令时,它将通过调用 fork 生成该命令表示的可执行文件。向新子进程打开一个管道,并且 shell 读取并打印其输出。此页面有 fork 和 pipeline 函数的完整示例...

This question is already answered in detail here.
Quoting verbatim from the same answer

A pipe is a mechanism for interprocess communication. Data written to the pipe by one process can be read by another process. The primitive for creating a pipe is the pipe function. This creates both the reading and writing ends of the pipe. It is not very useful for a single process to use a pipe to talk to itself. In typical use, a process creates a pipe just before it forks one or more child processes. The pipe is then used for communication either between the parent or child processes, or between two sibling processes. A familiar example of this kind of communication can be seen in all operating system shells. When you type a command at the shell, it will spawn the executable represented by that command with a call to fork. A pipe is opened to the new child process and its output is read and printed by the shell. This page has a full example of the fork and pipe functions...

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