Re: Three processes intercommunicating(both ways) using pipes, (six pipes??)
From: Pascal Bourguignon (spam_at_mouse-potato.com)
Date: 11/27/05
- Next message: Alex Vinokur: "Re: argv[0] in execvp()"
- Previous message: mirtoni: "Re: Three processes intercommunicating(both ways) using pipes, (six pipes??)"
- In reply to: mirtoni: "Re: Three processes intercommunicating(both ways) using pipes, (six pipes??)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 27 Nov 2005 17:19:29 +0100
"mirtoni" <mirton@gmail.com> writes:
> Thanx for the reply, but I'm sorry cause I have no idea what you wrote
> above. Is this some kind of pseudo-code.
Yes.
> I really appreciate the help,
> but I'm not good at low-level programming languages.
That's why I wrote higher level pseudo-code.
> While I was waiting for a reply I tried something like this:
>
> Two pipes to which the server process reads and writes to.
> And on the other end The Client and Process 3 will read and write to.
> This is because the information going through the pipes from one
> process will be the same for the other two processes.
> So when the server writes, he will have to write it twice with a little
> usleep(300) in between. And if one of the other processes writes, then
> the server will have to re-route the data to the other process!!!
>
> I still haven't got it going completely, but I hope you can offer me a
> better solution with identical information in pipes besides the one I
> wrote above..
Divide and conquer.
and abstract, abstract, abstract!
That means, don't try to solve several problems at once.
The fact that you consider a process being a server and the others
clients is irrelevant once you've specified you want them to
communicate in a ring of pipes: write a function that just builds this
ring of pipe.
Don't think your server as writting twice. Abstract! Have it write
once, and let the implementation deal with what is needed to have all
recipients receive the data. That means, instead of writting:
write(pipe[WRITE],...);
write:
tell_them(...);
and let the tell_them() function do what needs to be done.
Now, writting twice (or more, what will happen when you'll have 10
processes?!), may not be the most efficient way to multicast data to
processes on the same computer. You could try shared memory (with
semaphores). Then the tell_them() function would copy the data once
to a shared memory block, and increment a semaphore by the count of
recipients. The recipients will then be able to read the data
directly from the shared memory block, and decrement the semaphore.
When the semaphore reaches 0, all recipient processes have read the
data and the shared memory block can be reused for the next message.
-- __Pascal Bourguignon__ http://www.informatimago.com/ Cats meow out of angst "Thumbs! If only we had thumbs! We could break so much!"
- Next message: Alex Vinokur: "Re: argv[0] in execvp()"
- Previous message: mirtoni: "Re: Three processes intercommunicating(both ways) using pipes, (six pipes??)"
- In reply to: mirtoni: "Re: Three processes intercommunicating(both ways) using pipes, (six pipes??)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|