[英]Redirecting input and output of a child process in C
I want to write ac program in which i create multiple child processes and redirect their inputs and outputs to different file descriptors .I googled a lot but couldn't find relevant results. 我想编写一个ac程序,我在其中创建多个子进程并将其输入和输出重定向到不同的文件描述符。我搜索了很多但找不到相关结果。 Please help . 请帮忙 。
The answer depends on your operating system. 答案取决于您的操作系统。 On UNIX-like systems, you use dup()
and dup2()
to copy file descriptors around; 在类UNIX系统上,使用dup()
和dup2()
来复制文件描述符; each child process will inherit the current set of file descriptors from the parent when it is exec
-ed. 每个子进程在exec
时将从父进程继承当前的文件描述符集。 So typically you fork
the child process, set file descriptors 0, 1, and 2 to whatever you want them to be, and then exec()
the actual child program. 所以通常你fork
子进程,将文件描述符0,1和2设置为你想要的任何东西,然后exec()
实际的子程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.