Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating child processes in c for windows ---------------

Status
Not open for further replies.

DaniDak

Technical User
Mar 13, 2002
44
US
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.

 
Not sure why you want to do all this by spawning child processes. Why don't you make the program multi-threaded and do what you require on different threads?

You can get each thread to write a number to a 'queue' (STL will give you the code needed) and the main thread can then loop and read each 'queue' alternatively.

 
Hi,
A process in Windows is the running program. It only owns its virtual memory and its virtual registry, but does not do anything. In windows runs only threads. To create a new thread (as a new process in Unix by using fork) you will use function CreateThread. Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top