Hi,
I have a specific number of processes, which were created using fork(), those processes should communicate each with other using pipes. I want to create a dynamic array of pipes or use a Vector so it would contain all the pipes there were created.
each pipe should be of size of 2 integers so the array of the vector size should be arr[N][2].
my problem is that I don't know how to create properly this Vector or Array and pass it correctly to the dup2 function.
Maybe some one could help me with an example?
I build those two functions:
and tried to use vector, like this:Code:int** createArrOfPipes(int amount) { int** arr = new int*[amount]; for (int i=0;i<amount;i++) { arr[i] = new int[2]; } return arr; } void freeArrOfPipes(int** arr, int amount) { for (int i=0;i<amount;i++) { delete[] arr[i]; } delete[] arr; }
vector< vector<int> > pipes;
vector<int> read_vec1;
vector<int> write_vec2;
pipes.push_back(read_vec1);
pipes.push_back(write_vec2);
but how to do some thing like this:
or this:Code:for(int i=0;i<(sub_commands.size()-1);i++) { pipe(pipes[i]); }
Thanks in advance.Code:while (dup2 (pipes[(command_index-1)][read], STDIN_FILENO) < 0) //dup client's sock with stdin { if (errno == EINTR) continue; fprintf(stderr,"dup2 failed."); }



LinkBack URL
About LinkBacks


