pipe read and write with many forked children


 
Thread Tools Search this Thread
Top Forums Programming pipe read and write with many forked children
# 1  
Old 02-08-2005
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/
# 2  
Old 02-09-2005
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.
# 3  
Old 02-09-2005
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
# 4  
Old 02-09-2005
Its blocked because of I/0

answered my own question.

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

Steven
# 5  
Old 05-23-2007
good link

Hi, its a very good link, thanks and if any info u know pls share with the community.
# 6  
Old 05-23-2007
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

One parent, multiple children pipe with fork()

The task I have to do is something along the lines "I receive some input and based on the first character I send it through pipe to one of the children to print". The scheme it is based on is 1->2; 1->3; 1->4; 2 will print all the input that starts with a letter, 3 will print all the input that... (2 Replies)
Discussion started by: Ildiko
2 Replies

2. Shell Programming and Scripting

How to avoid ssh :Write failed: Broken pipe?

Hello, I am trying to run some code on Matlab over ssh . The code takes around 5-6 hours to complete. so after giving the command to run it , I locked my machine and then went off to sleep at night, only to discover in the morning that I get this message : ...Code running, partial results... (1 Reply)
Discussion started by: ajayram
1 Replies

3. UNIX for Advanced & Expert Users

write failed: Broken pipe

The "write failed: Broken pipe" message is reported by the file sending PC which run my writed network device driver while 500MB or 900MB is sended! What does the message mean? Does this mean there is a bug in my driver? li,kunlun (11 Replies)
Discussion started by: liklstar
11 Replies

4. Programming

Multiple children and single pipe

Greetings everyone, I need a bit of help in solving the following problem: I'm given an array of numbers and I have to compute the sum of the array elements using n processes, and the inter process communication has to be done with pipes(one pipe, to be exact). I managed to solve the problem... (14 Replies)
Discussion started by: ephesos
14 Replies

5. UNIX for Dummies Questions & Answers

Write to file using tail -f through a pipe to grep

Hi -- I'm looking to write to a file after piping output from tail -f through to grep: #write to a file for all lines with "searchtext" within in error_log: Expand|Select|Wrap|Line Numbers tail -f /var/error_log | grep searchtext > output.txt The above command... (2 Replies)
Discussion started by: ndedhia1
2 Replies

6. UNIX for Dummies Questions & Answers

echo: write error: Broken pipe ??

I want to try the unix pipe, the command is like this: echo new | find . the standard output of the echo should be "new", then I guess find command will use this output as input to find the file named "new". But the output is all the file names in my current dir, the last line is "echo: write... (5 Replies)
Discussion started by: andrewust
5 Replies

7. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

8. Shell Programming and Scripting

Write in a file with pipe also in same line

hi, i want to write in a file the output of one command and pile also the same output like ls -lrt > some_file | wc -l (9 Replies)
Discussion started by: narang.mohit
9 Replies

9. Shell Programming and Scripting

Find all files with group read OR group write OR user write permission

I need to find all the files that have group Read or Write permission or files that have user write permission. This is what I have so far: find . -exec ls -l {} \; | awk '/-...rw..w./ {print $1 " " $3 " " $4 " " $9}' It shows me all files where group read = true, group write = true... (5 Replies)
Discussion started by: shunter63
5 Replies

10. UNIX Desktop Questions & Answers

Wall, Write, select users, pipe a text file, HELP Before I'm Bald!

OK... I'm fairly new to unix having the admin handed to me on a platter w/almost no training. However, being a programmer, I do pick up things fairly easily, but this one is getting the best of me. I have a unix server that runs multiple versions of the same ERP system, hand crafted for our... (1 Reply)
Discussion started by: chimodel
1 Replies
Login or Register to Ask a Question