Skip to content
Advertisement

Forks and Pipes in c++

I am using 4 processes in which A’s output will goto A1 and A1’s output will go to A2 and A2 output will come out in the console. Even A1 output also will comeout in console.

  1. 1st program – A C++ program which is a random generator that will generate the output as per the requirements of A1’s input and also act as a collector for stdout from the sub processes
  2. 2nd program – Python script which will take the input of A’s output and will generate the output as per the requirements of A2 and the output of A1 should print in the console.
  3. 3rd program – cpp file which will take the input of A1’s output and will give the output and print in the control.

I am using 2 pipes – ABtoC for A to A1, A1toA2 for A1toA2.

Here A to A1 is working and A1’s output is printing in the console. But the issue is A1’s output is not going to A2’s input. Here is the below code I am using for this operation.

JavaScript

Insert ASCII graphics below:

JavaScript

Advertisement

Answer

When you launch A1, you are closing A1toA2[1] and then after that trying to dup it into stdout. Do all of the dups first, and then close what you don’t need.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement