简体   繁体   English

C ++如何创建/使用管道和分支?

[英]C++ How To Create/Use Pipe and Fork?

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. 我需要学习如何在VC ++ 2010中创建pipe并使用fork ,以及如何写入piperead

Are there any tutorials on how to do that? 有没有关于如何做到这一点的教程?

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. 在所有操作系统shell中都可以看到这种通信的熟悉示例。 When you type a command at the shell, it will spawn the executable represented by that command with a call to fork. 当您在shell上键入命令时,它将通过调用fork生成该命令所表示的可执行文件。 A pipe is opened to the new child process and its output is read and printed by the shell. 管道将打开到新的子进程,其输出将由shell读取并打印。 This page has a full example of the fork and pipe functions... 这个页面有一个完整的fork和pipe函数示例......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM