Reputation: 716
I want to write a c 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. Please help .
Upvotes: 3
Views: 3180
Reputation: 3366
My favorite is forkpty. This function forks a child and give you a file descriptor to its stdin/stdout. You can use exec after forking,
Upvotes: 1
Reputation: 27542
Start with dup. You really need to search a bit harder. There is plenty of material on this.
Upvotes: 3
Reputation: 81674
The answer depends on your operating system. On UNIX-like systems, you use dup()
and dup2()
to copy file descriptors around; each child process will inherit the current set of file descriptors from the parent when it is exec
-ed. 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.
Upvotes: 2