如何在c ++中创建一个管道 [英] How to make a pipe in c++

查看:116
本文介绍了如何在c ++中创建一个管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看一个c ++程序的代码,它管理一个文件的内容更多。我不太理解它,所以我想知道是否有人可以写一个c ++程序的伪代码管道东西到别的东西?为什么需要使用fork?

I'm looking at the code for a c++ program which pipes the contents of a file to more. I don't quite understand it, so I was wondering if someone could write pseudocode for a c++ program that pipes something to something else? Why is it necessary to use fork?

推荐答案

create pipe
fork process
if child:
  connect pipe to stdin
  exec more
write to pipe

您需要 fork(),以便您可以在调用之前替换子进程的stdin,这样您就不必等待进程继续。

You need fork() so that you can replace stdin of the child before calling, and so that you don't wait for the process before continuing.

这篇关于如何在c ++中创建一个管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆