LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-13-2005, 01:57 PM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
how to do one to many inter process communication?


hiho@ll

i have a configserver running inside my app
the app itself has a forked child processes

i now want that every process is configurable through a webinterface
so i thought about creating one configserver which listens for a tcp connection
and every forked process creates a configthread

the configserver then sends data through a fifo to the configthreads and the threads answer to the server

well
i'm working on this for days and i have many problems with the fifo communication cause there are many threads who want to send their data to a the server back and i don't receive the stuff on configserver side (i have no idea why or how i could explain the problem in more detail)

anybody has another idea how to solve such stuff?
maybe another method of IPC?
or some hints for working with fifo pipes would be cool

thx@ll
 
Old 12-13-2005, 07:00 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I've done something similar using Perl and TCP. Had probs with FIFOs. If you allow the machine to talk to itself via the loopback i'f (ie lo) you can do it this way. Also means you could later communicate from a remote machine.
 
Old 12-14-2005, 03:54 AM   #3
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Original Poster
Rep: Reputation: 30
@chrism01
yeah, its a good idea to do this so you can do remote config too
i thought about this, but i don't want this to be a security hole

now it doesnt matter cause
it works!

fifo's aren't the easiest way to solve this kind of stuff

the problems i had with the fifo stuff:
i read many simple examples and i did some examples which worked good
then i tried to implement it to make something like a "fifo-configuration infrastructure"
the goal was to be able to configure every process of a server seperately
so i could for example change the serverport on the fly (thats cool!)

the problems i had where:
the configserver sends the config request to its fifo-childs and each child reads it using a configthread
the thread does the configuration and sends a response back to the server!
the response was my biggest problem

first i didn't understand why a FIFO is a half-duplex pipe!
so if you want a full duplex fifo, you have to create 2 fifos
if you open the fifo O_RDWR it's only a half duplex pipe, so if the same process writes something and reads again it will read what it wrote!

the second problem i had was that the configthreads write some data in the serverpipe but it wasn't created already
it was because every example i read did a mkfifo and in the next line a open(); so i didn't think about using this seperately
i was sending the request to the threads, did a mkfifo and opened and i only got some responses with a bit luck, because the pipe was opened too late
now i do a mkfifo, send the request, open the fifo O_RDONLY and read the response ;-)

the third problem was i didn't know what happens to my server fifo if many childthreads try to open the fifo using O_WRONLY
and now comes a really tricky part
if the server does a mkfifo
then sends the request
and the clients open the pipe, write the response and close it!
the END OF FILE is getting sent too!!
this means, if i send the request to 2 childthreads and both threads write the response and
then i read from my serverfifo, the read(); returns 2 times 0
so i read
first read: "RESPONSE"
second read: returns 0
third read: "RESPONSE"
fourth read: returns 0
so i made it part of my protocol: i send the request to the childthreads and i count how many childs got the request (if(write()>0) count++)
then i checked how often read returns 0 (readcount++)
if readcount==count i got every response
this method seems to work very well
 
  


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
inter-program communication Raspis21 Programming 9 07-22-2005 02:49 AM
KDE: Inter-process authentication problems elempoimen Linux - Software 1 06-10-2005 10:48 PM
Process Communication erdemilhan Programming 1 11-27-2004 04:06 PM
process communication between linux and xp naanu Linux - Networking 2 03-10-2004 12:54 PM
Need a challange?!? Try to solve this one: INTER PROCES COMMUNICATION rkrijger Linux - Software 1 10-29-2003 09:43 AM

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

All times are GMT -5. The time now is 07:32 PM.

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