Reputation: 13
I want to write two c++ application the first one called "caller," the second called "processor."
caller application send a value to a processor. after that processor do some process on that value and return it back to caller.
I want to know the best way to do that.
so far I know how to send value from caller application to processor application but I could not find any way to return the value back. one of this way by using putenv() and getenv()
caller example
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char **argv, char** envp){
char myvar[]="MYVAR= say something";
putenv(myvar);
cout<<getenv("MYVAR")<<endl;
system("./processor");
cout<<getenv("MYVAR")<<endl;
}
processor example
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char **argv, char** envp){
char myvar[]="MYVAR= say something else";
putenv(myvar);
cout<<getenv("MYVAR")<<endl;
}
how to fix that to return value from processor to caller and if there is better way what is it. I am using Ubunut OS.
Upvotes: 1
Views: 798
Reputation: 753695
There are many possible ways to communicate between to processes, and which is best depends on a lot of factors. Using the environment is basically only good for one-way communication, not bidirectional communication. The methods available include:
Some are limited to processes connected by a common ancestor; others can work between unrelated processes, sometimes not even on the same machine. Some mechanisms can communicate very little data (signals, for example); others can communicate large quantities of data. Some require no synchronization; others require extensive synchronization.
Which is best for you? We don't have enough information to guess. However, your best choice is most likely between pipes, files and sockets.
Upvotes: 2