The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Wall, Write, select users, pipe a text file, HELP Before I'm Bald! chimodel UNIX Desktop for Dummies Questions & Answers 1 03-13-2008 01:50 PM
Problem in read() from a pipe JDS High Level Programming 2 10-13-2006 07:19 AM
AIX 5.3 - There is no process to read data written to a pipe vigsgb UNIX for Advanced & Expert Users 4 06-21-2006 01:09 AM
read after pipe problem OSX10.4 relyveld Shell Programming and Scripting 5 07-07-2005 05:56 PM
read, write & STDOUT_FILENO.... M3xican High Level Programming 2 07-17-2002 01:41 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-08-2005
Registered User
 

Join Date: Jan 2005
Posts: 6
Stumble this Post!
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/
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-09-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,849
Stumble this Post!
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.
Reply With Quote
  #3 (permalink)  
Old 02-09-2005
Registered User
 

Join Date: Jan 2005
Posts: 6
Stumble this Post!
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
Reply With Quote
  #4 (permalink)  
Old 02-09-2005
Registered User
 

Join Date: Jan 2005
Posts: 6
Stumble this Post!
Its blocked because of I/0

answered my own question.

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

Steven
Reply With Quote
  #5 (permalink)  
Old 05-22-2007
Registered User
 

Join Date: Feb 2007
Location: bangalore
Posts: 4
Stumble this Post!
good link

Hi, its a very good link, thanks and if any info u know pls share with the community.
Reply With Quote
  #6 (permalink)  
Old 05-23-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
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?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0