| vincegata (72) | |
|
Hello, If I implement two apps using asynchronous I/O ( select() ) so both apps will write into stdout and they will read each others output, is going to work? I guess it's not possible to implement such thing just using pipes & output redirection? -Thank you. EDIT: I need a bidirectional communication between two processes, one of them is multithreaded. | |
|
Last edited on
|
|
| eraggo (124) | |
|
AFAIK the thing is that each program starts in different process. Processes haves their own stdins/stdouts controlled via OS. -e- | |
|
|
|
| kbw (5375) | ||
See the example here where one program spawns another (ls in this example) and talks to it over a pipe. http://pubs.opengroup.org/onlinepubs/009604499/functions/popen.html I forgot to add the link, oops. | ||
|
Last edited on
|
||
| vincegata (72) | |
| Hi kbw, what example? | |
|
|
|
| vincegata (72) | |||
By pipes I meant:
| |||
|
|
|||
| vincegata (72) | |
| kbw, I got your example, it's uni-directional for reading only. I need a two-way communication to read/write. I guess I have to open two pipes - one for reading and another for writing. Not sure how - trying to google for now. If you also have a two-directional sample please post. Thank you. | |
|
|
|
| kbw (5375) | |
|
Sorry, wrong example. Take a look at this. http://pubs.opengroup.org/onlinepubs/009604599/functions/pipe.html | |
|
|
|
| vincegata (72) | |||
|
I got it - it works! Is it also possible to read from stdin, meaning while these two apps communicate through the pipes with each other, I could also enter a command to send it to a child?
| |||
|
Last edited on
|
|||
| kbw (5375) | |||
Is this what you want? bc is controlled from the parent, which echoes commands from stdin.
| |||
|
|
|||
| vincegata (72) | |
|
Not quite - I want the parent and child to keep communicating. So in the code from my post it should keep printing the value of 2^32 every five seconds, but I'd also like to be able to enter my own expression in between those five seconds so it should be send to bc for calculation and the result should be sent back. So, the output would be like: 4294967296 <- start 4294967296 <- 5 sec 2^4 <- I manually entered this at e.g. second 6 16 <- bc calculated this 4294967296 <- second 10. kbw, I appreciate your help, you do not have to code it for me just point in the right direction, unless it takes you like 2 minutes :). I am a bit stuck in here to tell the truth. I am going over Richard Stevens right now but I do not see he has what I need, books differ from real life. Thanks again. | |
|
Last edited on
|
|
| kbw (5375) | |||
You could use alarm() to send a SIGALRM signal every five seconds.
| |||
|
Last edited on
|
|||
| vincegata (72) | |
| It works, just one question, if I press Enter without providing any input it won't take any more input from me so I have to restart the program, do you know why is that? - THX | |
|
Last edited on
|
|
| kbw (5375) | |
| It's the beviour of bc. If you want to fix it, you have to validate the string passed to bc on the pipe. | |
|
|
|
| vincegata (72) | |
| I can catch Enter but bc run on its own takes Enter no problem, I'll look it at more. | |
|
Last edited on
|
|
| vincegata (72) | |
| kbw - thanks a lot for your time! | |
|
|
|