Inter-process communication
BlitzMax Forums/BlitzMax Beginners Area/Inter-process communication
| ||
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? |
| ||
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 |
| ||
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. |
| ||
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. |
| ||
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. |
| ||
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? |
| ||
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... |
| ||
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... |
| ||
ok. thanks, I will try. |
| ||
You can send update values to the client(s). master.bmx proc.bmx |