pipe read and write with many forked children

I know how to read and write if i have a forked process with only one child. However what is involved with reading and writing with many forked processes. Say one parent that forks 5 children, and needs to communicate with all 5 in half duplex.

int temp[2], counter=0;

do{
pipe(temp);

if(fork()>0){
//store values of temp in a 2 dimensional array then re-index the array @ counter.
}
counter++
}while(counter<5);

Then if i access each the 2 dimensional array at location array[0][1] i cold write to child 1, and read child 1 at array[0][0];

Is there an easier way?

Im gong to implement this shortly, please let me know if im on the right track.

thanks for your time,

New to unix and c/

Probably a better choice: shared memory and a semaphore

There is a nice free online book about advanced programming that might help you -

http://www.advancedlinuxprogramming.com/alp-folder

Try chapter 5 on 'Interprocess Communication' - there are examples.

Hey thanks that was a great link, lots of good info for the future.

But anyway, im using pipe and my initial idea is working great except one flaw.

The parent process will sit on a read until there is available data. How to get him to go on if there is not data, not keep waiting?

Thanks for any help,
Steven

Its blocked because of I/0

answered my own question.

Use poll() or select(), incase anyone ever searches this thread.

Steven

Hi, its a very good link, thanks and if any info u know pls share with the community.

  1. only one process can read a pipe at any time, multiple can write.

  2. scalability, if you want more processes that allowable file descriptors per process what do you do?