IPC on Linux

So, I'm currently working on a project that, in the simplest way possible, can execute another .out file and give or take variables from it. After awhile of searching the internet, i found a few methods such as sockets, shared memory, and pipes. Throughout every "tutorial" i read on how to use them, they never gave any real instructions on how to use it within a program. they just gave an example code, with a non-helpful description that got me nowhere. What i need is for someone to help me actually get it to work. All i need is for the .out files to be executed from one .out file in a branch, with the ability to exchange variables. Also, having originally tried system, I'd appreciate if the method used only allowed one part to run at once. The later processes are going to require variables from the earlier ones, so it'd be a big help. Thanks in advanced for reading this, and hopefully helping with the problem ^^
wow. thanks everyone for being so helpful with a simple problem...
We'd love to be more helpful, but apparently you haven't the time it takes to get a worthwhile answer.
well, ive seen people get help in an hour, its been over 24 and nobody besides you even commented on it. i dont really see how i could provide more information to this. i want to add the functionality myself, so i know how to do it, id just appreciate a more how-to-implement focused explanation of it. the project im working on is completely reliant on that, and its at a halt until i can figure out how. and sorry i got pissed its just that i see people getting help instantly and this is supposed to be something easy. o.o
I have to work right now. Later today I'll see if I can find something that is useful to you.
thanks alot.
When you say "exchange variables", what do you mean exactly. You complain that the examples your seen don't provide adequate instructions. But you fail to state your needs explicitly. Do you need to exchange an integer or two, or get back a string? Or do you need to pass complex objects back and forth?

Personally, I recommend "Advanced Programming in the Unix Environment, 2nd Ed." by Stevens and Rago as a "must own" book for anyone doing this level of programming on Unix.

At the simplest level, you can use popen() to pass arguments to programs on the command-line and read the results written to stdout via the file descriptor returned by popen().
hmm, i thought exchange variables was explicit enough.
i need the program to run another, wait for it to return, and carry back a few integers. then i need it to launch ANOTHER program and carry those integers to it, then that program uses the integers for various things. so its like : A>B>A>C. get it? variables are picked up at B. brought back to A, then carried to C. yes i know it seems kind of odd for having the stop in A, but its to add later functionality for the program.

in the long run, it'll be setup like this :
A is a menu of sorts.
A launches B, brings back the variables.
A launches C, brings back the variables.
A launches D, brings back the variables.
A launches E, carries the variables over for use.
B C and D are seperated to categorize the variables, and like i said : for later editing/adding functionality.

Sorry, just thought that variable exchange was kind of clear.
And really, even variable exchange was more clear than some of the "instructions" i read. i wouldn't call them instructions though, they just spit out various code. tells you what it means. then end. which isn't helpful unless you're building the code off of that. and im not gonna go ahead and rebuild what else i have from that. but popen doesn't seem to be what i need, kinda far from it, but atleast offering the help was good, hopefully you'll have something up your sleeve that can do what i need :D

[EDIT]
However, you did solve that problem of A to E. :) just need a way to pull the variables out, but what exactly would be the code i'd put on E.
i get that in A, i'd show : popen(bob, john, monkeys, cats, whatever, other, variables, etc), but how exactly would i read the results? im relatively new to C++, even more new to something like this. never bothered to make a multiple-file system, usually just do stuff in one file.
Last edited on
It seems to me that a simple file would do the trick.
You could even use a temporary file (obtained with tmpfile() or tmpnam()) which you pass to the child programs via commandline.
[EDITED FOUR TIMES]
thats what i was thinking originally, just not sure how to get it through.
use tmpfile(-filename-) on B C and D then have E use a stream to read it as if it was (or it actually is) a text file?
this is gonna be a bit hypocritical, but can i have an example code of something like that? :P
as for why im being hypocritical... or rather, what was wrong with the examples was that they were really complex pieces of code to get the thing done, and i had no clue how to put it in. obviously i was just barking up the wrong tree. i tried looking for stuff like that but all i found was sockets, shared memory, etc. which wasn't a simple one-line code o.o also, it seems that socket is for communication through different computers? or one of them was. that, or it justed used TCP for no apparent reason o.o

[EDIT]
also another response to pangalactic's comment.
i was not at all referring to the tutorials or references on this site, in case you thought i was. i found those extremely useful in getting started with C++.

[SECOND EDIT]
my friend is explaining it to me, thanks guys :D

[THIRD EDIT]
ahhhhhh!!!!! tmpfile first off, isn't allowed by my compiler. mkstemp is though. besides that, a few problems.
aren't temp files deleted when the application is closed? how do i get a stream to the temp files to get the variables from em? and im guessing ill have to use a stream to write to them as well. not sure how. (my friend had to go, couldn't get the whole explanation D:)

[FORTH EDIT]
couldn't i also just use one of the open()'s to create a few files in the temp folder, then modify them and use em when needed. so they aren't actually tmpfile() files, so they aren't removed on exit, but they are still in the temp folder, which if i remember correctly, is cleared on reboot on UNIX. not to mention it's pretty small integers only, not gonna be big. the only integers that could potentially be huge are ones that are formula based and are calculated on the spot by the application. but even then, how can i stream a file that's WAY back in the file system. /tmp/file name.file extension would be the location of it. the file that needs it would be in someone's home directory or on their desktop (which is part of the home directory... i believe...?) how would i get to those files?
Last edited on
sorry, this used to contain information. im changing it now. i solved the problem. i was originally using ifstream::get() but i realized i should just use input into a variable. it worked :) ive got it working now. thanks for all the help.
Last edited on
Topic archived. No new replies allowed.