LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-06-2010, 05:53 PM   #1
golmschenk
Member
 
Registered: Nov 2009
Posts: 144

Rep: Reputation: 15
C - Using pipes with a parent that has multiple children


If I were to make a parent who forked to having multiple children, how do I run the pipes in this kind of situation? For the particular case I'm looking at, I'd be happy with all the children receiving the same information from the parent at all times. For this am I able to do something similar to the example here:
http://tldp.org/LDP/lpg/node11.html
Except fork more then once? So that in the end it would be as if it's just one pipe but it leads to two children? So that anything sent through the pipe would be received by both of them? If not, how could I go about setting up such a situation? Thanks for your time!
 
Old 03-06-2010, 06:06 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

As far as I know, the relationship between parent and child(ren) with Linux pipes is 1::1. I'd be interested if you find otherwise.

One "classic" solution of 1::many IPC (between any two processes, not just parent/children) is shared memory. Another might be UDP multicasting.

Linux supports a relatively new feature, "tee()", that might also permit you to send the *same* message to *multiple* open pipes:

http://linux.die.net/man/2/tee

'Hope that helps .. PSM
 
Old 03-06-2010, 06:49 PM   #3
golmschenk
Member
 
Registered: Nov 2009
Posts: 144

Original Poster
Rep: Reputation: 15
How do you assign the pipes to the children then? At least in the example I gave there doesn't seem to be any point at which you assign it. The child is just able to use them

Last edited by golmschenk; 03-06-2010 at 06:51 PM.
 
Old 03-06-2010, 07:33 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by golmschenk View Post
If I were to make a parent who forked to having multiple children, how do I run the pipes in this kind of situation? For the particular case I'm looking at, I'd be happy with all the children receiving the same information from the parent at all times. For this am I able to do something similar to the example here:
http://tldp.org/LDP/lpg/node11.html
Except fork more then once? So that in the end it would be as if it's just one pipe but it leads to two children? So that anything sent through the pipe would be received by both of them? If not, how could I go about setting up such a situation? Thanks for your time!
You might consider using named pipes:

man 3 mkfifo
.

Still the parent (i.e. source of info, the broadcaster) will have to write into each named pipe separately, i.e. the children won't receive info simultaneously. Anyway, with a single CPU/core they physically can't receive info simultaneously - only one child (if any) is in fact executed at any given moment of time.

You can achieve better synchronization by writing one word (the word being the atom you want to send, e.g. an FP number) at a time into each named pipe - rather than the whole buffer of words.

You'll need to start the children first, to be more exact, the children (listeners) should start listening before the broadcaster starts writing into named pipes.

Last edited by Sergei Steshenko; 03-07-2010 at 03:53 PM.
 
Old 03-06-2010, 07:34 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Another thing - I vaguely remember Qt library has slots - I think they will serve your purpose too, look them up.
 
Old 03-07-2010, 03:30 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Sergei Steshenko's suggestions, particular about "named pipes", are good ones.

ALSO: have you considered DBus:

http://dbus.freedesktop.org/doc/dbus-tutorial.html

http://www.ibm.com/developerworks/li...ry/l-dbus.html

'Hope that helps .. PSM
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gnome/gdm startup apps: Why are some children of gdm and others children of init? sixerjman Linux - Software 1 07-04-2009 10:48 AM
File descriptors shared between child and parent causing parent to hang. bharadiaam Linux - Newbie 1 03-02-2009 01:01 AM
Finding all your children Curtor Programming 5 12-09-2008 07:00 PM
How many children have been created... maniac01 Programming 8 03-11-2004 11:27 AM
Multiple 100mb pipes on 100mb switches DLinkOZ Linux - Networking 2 10-22-2003 11:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration