hi,
how would one pass a vector to a forked process and afterwords collect the data from that array:
example:
Code:
using namespace std;
int main (){
pid_t pid;
int status;
vector<pid_t> pidarray(2);
vector<int> vec(10,0);
vector<vector<int>> a(2,vec);
for (int i = 0; i< 2; i++){
pid = fork();
if (pid == pid_t(0)) {
for(int z = 0; z < 10;z++){a[i][z] = z;}
exit(0);
}
else if (pid > pid_t(0)){
pidarray[i] = pid;
}else{
cerr << "failed\n";
exit(1);
}
}
for(int i =0; i<2;i++)
waitpid(pidarray[i], &status, 0);
cout << endl;
for(int i =0; i< 2; i++){
cout << endl;
for(int z = 0; z <10;z++){
cout << a[i][z]<< endl;
}
}
return 0;
}
so i would like for my results obtained in forked processes to be in my a vector. Is this possible to do ??
thnx