am currently reviewing old tests in order to prepare myself for my final exam.
i will be the first to admit it: i suck at fork()ing and piping . i suck at them b/c i have a hard time understanding their behavior.
so i have been reivewing like a fiend and feel comfortable with fork()ing and/or pipe()ing, so long as the two are not combined.
so with that said - can someone explain how i could approach a problem such as this:
mind you this isn't the only question that i am having difficulty with, but i don't wanna seem like a major whine bag. but if someone could point out which way the light is at, i would appreciate it.Write a C program which will create a total of 37 processes all of which will have their own separate pipe. i.e. all processes will be able to write to all other processes but each processes will only read from its own pipe. In addition, each process will have an assigned index, 0...36.
Each processes will check it's pid and if its pid is even, it will write its pid to each of the processes with even indicies, while, if its pid is odd, it will write its pid to each of the processes with odd indices (but no process writes to itself). Then each process will read all the messages written to its pipe and print on stdout, for each message, a line similar to:
Procedss 35894 heard from process 35992
Be careful that your code doesn't hang!