Inter-process communication

BlitzMax Forums/BlitzMax Beginners Area/Inter-process communication

Queller(Posted 2008) [#1]
It has come time for me to get into inter-process communication. I want to have one program, "parent", that is managing a bunch of others running as seperate "child" processes. From the freeprocess module, as I understand it, I can read and write to a child process by attaching a TProcess to it and treating the TProcess like a stream. My question is how does one prepare the child program to be communicated with in the first place? As far as I can tell, I am supposed to open a TPipeStream in the child and read from/write to that, and if another program is listening/writing to the pipe then that is how communication takes place. Is this correct?


Dreamora(Posted 2008) [#2]
TProcess is not attached to the child process ... it actually is the child process or better executes it and takes care that it isn't not just freed again.

From the host, you use TPipeStream to communicate (TProcess holds one in process.pipe ...)
In the child you use StdInStream / StdOutStream


Queller(Posted 2008) [#3]
Okay, thanks for the clarification. One other thing, if I may; I noticed in FreeProcess that there is a std pipe and an err pipe to communicate through. On the child side how do you direct which pipe to write to? If I have an error in the child program then I definitely want to be able to control the stream message out so it goes to err pipe not std pipe, for example.


Dreamora(Posted 2008) [#4]
Never checked the error pipe. Perhaps that are system signals (you would need to check that) which BM does not allow you to send. You would need to write some own functionality for this purpose.

Or you are right in the way that it is possible to create a TPipeStream in the client without having a valid TProcess to use those 2 streams ...
So far I've always used the StdIn and Out so I can't say, sorry.


Queller(Posted 2008) [#5]
Alrighty, after some messing around I have arrived at this, but can someone tell me where I am screwing it up? Messages should be exchanged through pipes and appear in the complimentary text fields upon entry.

Child exe



Parent exe



Obviously the child.exe has to be compiled first and then wait in the same folder as the parent.exe so parent.exe will be able to find and run it.


degac(Posted 2008) [#6]
I'm playing with inter-process comunication and I'm blocked with ReadStdIN() function.

Have a look at the following example (master+client)
Master


Client 1 (proc_client) - this work perfectly



client 2 (proc_client with MaxGUI)


The problem is in the second client that uses MaxGUI - I think ReadStdIN() locks the program (and so MaxGUI processes) to wait some inputs: is there a workaround?


Queller(Posted 2008) [#7]
degac, when trying out your examples, for me both clients block at attempting ReadStdin(). I found an explanation about the blocking here: Link

That behaviour is exactly why I want to use non-blocking pipes instead...


ziggy(Posted 2008) [#8]
you should use plain text to comunicate processes. Just use readline and writeline. convert everything to strings. Standard IO streams work in a 4096 kbytes buffer and has a sort of interruption on CR characters. Also, I think non blocking pipes requiere multiple threading...


degac(Posted 2008) [#9]
ok. thanks, I will try.


plash(Posted 2008) [#10]
You can send update values to the client(s).

master.bmx


proc.bmx