LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
 
LinkBack Search this Thread
Old 09-19-2005, 09:25 AM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
pipe to many processes?


hiho@ll

this is very simple, but i don't really know the solution

i'm sure everybody knows the example
many processes have pipes to a server and give the server a command, which is executed by the server

that's easy:
open a pipe
make child's using fork();
and now the child sends a command using the pipe and the server receives it

how does the oposite way work?
i open a pipe
fork(); some childs
a child (everytime it's the same child who does this) then sends a command
and many other childs receive it!

the problem i have
if one forked() child receives the message
no other child receives it, because it's already read by the other child

it's like:
the first child who get's notified (by the select(); method) and reads the data
deletes the data so no other child can read it
well this makes sense: how do you know if the data in the pipe should be deleted for the next command which should be sent?
BUT that's a problem for me

i need a pipe where i can notifie many childs at the same time
anybody knows such a pipe? or another way i can send messages or commands (the size is variable) to my childs other than a socket server (because it's slow)?
hmm
maybe i have to use a AF_UNIX udp broadcast
but then i have to do message synchronization so they are received in right order

thx@ll
 
Old 09-19-2005, 01:29 PM   #2
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 573

Rep: Reputation: 91
Can you clarify your terminology? I don't know whether you're talking about interprocess communication on a single machine, or whether you're talking about network communication from multiple machines? I also can't tell whether you're talking about pipes (I/O streams between processes on the same machine) or sockets (network I/O streams). You're mixing design and implementation as well. Use high level concepts, please. (IE: You have a task that listens for connections. When it hears a new connection request, it creates a new task to handle the new connection. That's a design. The implementation would be a process that listens and then fork()'s a child handler when a new request is heard.)

The way I see it, you want to build a distributed network of peers. In that case, you have a few different approaches:

#1 - UDP broadcast signaling messages. These messages can signal some site B to do something for or related to A, and then have B create a socket back to site A.

#2 - Have a shared list of peers. This can sent via broadcast, or via central server. The systems on this list will connect to each other, so that all machines are connected to all other machines.

#3 - Have a mix mode, where there are peers which connect to an ultra peer. These will be called peer groups. Then be able to connect peer groups via ultra peer grouping.
 
Old 09-20-2005, 02:46 AM   #3
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Original Poster
Rep: Reputation: 30
1. yes, i'm mixing the terminology because i didn't find a IPC method which can do what i want, so i think there isn't one
2. i'm mixing design and implementation
because i just wanted to describe what i need (design) and asked for the implementation

well, it was my fault if i didn't clarify myself good enough

here another explanation:
1. my problem is only on localhost! no other IP's no other CPU's
just one server
2. i need a "one-to-many" IPC solution

the only thing that seems to work for one-to-many is udp broadcasts
that's why i was talking about this
because i can also do a localhost udp broadcast
one process sends "Hello, i'm process 1" using udp broadcast and many processes answer "hello, i'm process2","hello i'm process 3", "hello i'm process 4"

why i was talking about pipes:
i tried this with pipes, but i only got a one-to-one IPC
the first process who got the message answered
and this could be process 2 or process 4
it depends on which process got the cpu

why pipes?
because i think they are faster and more flexible (than udp broadcast) and i only need a solution for localhost

just to answer your question, here is the design (simplified):
one task listens (a server)
other tasks need to know what the server got --> server has to send information at the same time to many processes
why at the same time? because the server doesn't know who is listening/who want's to know

the approaches you claimed are possible for my problem
but see it this way:
i'm asking here because maybe there is a better, faster and flexible way which i don't know
 
Old 09-20-2005, 09:08 AM   #4
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 573

Rep: Reputation: 91
IPC doesn't allow you to have multiple listeners get the same message. However, you can have multiple processes listening on the same queue. You can send the same message with a different message type. Have it so that there is a base message type 0 for the pilot. Make your new programs write a message saying "I'm here" basically. The master program will then write a reply saying "You get message type (X)" The new program will then only listen for messages of the chosen "type." Hence, you can get the same message to multiple clients.

man msgrcv, and msgsnd. msgbuf->mtype is the field I'm talking about.
 
Old 09-20-2005, 11:22 AM   #5
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Original Poster
Rep: Reputation: 30
hmm
then i do the message queue implementation later

thx!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2-way pipe saiz66 Programming 3 11-22-2004 07:54 AM
monitoring active processes and identifying the required processes. gajaykrishnan Programming 2 08-13-2004 01:58 AM
pipe jelly Slackware 2 03-05-2003 03:07 AM
pipe using no pipe soathana Programming 2 02-22-2003 04:33 PM
pipe commands into processes acren Linux - Newbie 1 07-04-2001 10:08 AM


All times are GMT -5. The time now is 06:46 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration