Hi,
I have never done this before in c or c++ for either unix or windows, so any help is very appreciated.
I need to have a main program(parent that creates two child processes after creating two pipes to communicate with them.
- The first child has to generate odd numbers from 1 to 49 pausing for a random time 0 to 999 ms after each.
- The second child has to generate even numbers from 2 to 50 pausing for a random time 0 to 999 ms after each.
- While each child process puts its generated numbers on its own pipe, the parent (original main program) has to go around a loop checking for the next available number in sequence (alternating between the pipes) and printing it out when it finds it; each time around the loop, it pauses a random time 0 to 499 ms.
- I was thinking of using _pipe and _spawnl functions to create the pipes and child processes, and Sleep to pause each process, but the problem is that I have never done this before. Another thing, I have to pass the appropriate "read handle" to each process as a command-line argument, and a command-line argument so each child will know which one it is.
Thank you.
I have never done this before in c or c++ for either unix or windows, so any help is very appreciated.
I need to have a main program(parent that creates two child processes after creating two pipes to communicate with them.
- The first child has to generate odd numbers from 1 to 49 pausing for a random time 0 to 999 ms after each.
- The second child has to generate even numbers from 2 to 50 pausing for a random time 0 to 999 ms after each.
- While each child process puts its generated numbers on its own pipe, the parent (original main program) has to go around a loop checking for the next available number in sequence (alternating between the pipes) and printing it out when it finds it; each time around the loop, it pauses a random time 0 to 499 ms.
- I was thinking of using _pipe and _spawnl functions to create the pipes and child processes, and Sleep to pause each process, but the problem is that I have never done this before. Another thing, I have to pass the appropriate "read handle" to each process as a command-line argument, and a command-line argument so each child will know which one it is.
Thank you.