I have a project that I have to create a parent process with two children processes using spawnl and _pipe in c. I been looking all over the net for a easy toturial but no luck. So I hoping someone here can help. I need one child to count from 1 to 49 showing only odd numbers and the second child to count for 2 to 50 showing only even numbers. The parent process needs to go back and forth between the two child processes with a random pause between them using sleep. This really has me stumped. Any help would be greatly appreciated.
Using spawnl and _pipe in c to make two children processes?
So, the only problem here is that you don't know how to use the spawn and pipe functions?
Or you're having problems with the whole algorithm?
If you write the program in pseudo-code, you can figure out the algorithm quite easily. From your pseudo-code, you can figure out which C functions you will need. For example, since you need a random pause, you'll need to use something like rand() to make a random number. If you use rand(), you'll also have to use another function to seed rand(), otherwise, rand() will always come up with the same numbers each time you run the program.
I'm not going to do your homework for you by providing a complete program, or telling you how to make the algorithm. There are plenty of code examples for spawnl in web sites and there forums if you do a Yahoo! or Google search. If you're having trouble, you should post your code and ask for a solution to a particular problem.
Hint:
When you're learning new functions, first write a small test program with them to see if you can get it working. After that, you then work the functions into the program that you're making. Often, you can just copy %26amp; paste the code between the source files.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment