Results 1 to 1 of 1
I am trtying to implement multiple pipes..I am going wrong somewhere,,,
please help..
Code:
int executePipeFunctionality()
{
int fildes1[2];
int fildes2[2];
pid_t first, second;
int index = 0, initIndex1 = ...
- 10-14-2010 #1Just Joined!
- Join Date
- Oct 2010
- Posts
- 2
Multiple PIPE implement
I am trtying to implement multiple pipes..I am going wrong somewhere,,,
please help..
Code:int executePipeFunctionality() { int fildes1[2]; int fildes2[2]; pid_t first, second; int index = 0, initIndex1 = 0, initIndex2 = 0, innerIndex = 0,j=0,k=0; char* arg1[MAXITEM] = {NULL}; char* arg2[MAXITEM] = {NULL}; char* COMMAND_ARRAY[20][20] = {NULL}; int returnValue = 0; enum PIPES { READ, WRITE}; int * readDes[NUM_PIPE_INSTANCES+1]; int * writeDes[NUM_PIPE_INSTANCES+1]; //pid_t* pids[NUM_PIPE_INSTANCES+1]; int i=0; printf("NUM_PIPE_INSTANCES: %d\n", NUM_PIPE_INSTANCES); printf("INPUT_SIZE: %d\n", INPUT_SIZE); for (i = 0 ; i < INPUT_SIZE ; i++) { if (strcmp(GLOBAL_WORD_ARRAY[i], "|") == 0) { j++; k=0; } else { COMMAND_ARRAY[j][k] = (char*)malloc(sizeof(char) * strlen(GLOBAL_WORD_ARRAY[i])); strcpy(COMMAND_ARRAY[j][k], GLOBAL_WORD_ARRAY[i]); k++; } } for(j=0;j<2;j++) for(k=0;k<2;k++) printf("^^%s^^",COMMAND_ARRAY[j][k]); //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ int fd[10][2]; int status; int isFirstPipe = 1; int pid[10] = {-1}; int count = 0; for(i=0;i<NUM_PIPE_INSTANCES ; i++) { if(pipe(fd[i])<0) { perror("Error in Pipe creation"); return; } } fprintf(stdout,"here"); if(fork()==0) { for (i=0;i<=NUM_PIPE_INSTANCES;i++) { if(fork()==0) { if(i==0) //just write to pipe { close(fd[i][0]); dup2(fd[i][1],1); close(fd[i][0]); execvp(COMMAND_ARRAY[i][0],COMMAND_ARRAY[i]); } else { dup2(fd[i-1][0],0); execvp(COMMAND_ARRAY[i][0],COMMAND_ARRAY[i]); } } else { close(fd[i][1]); dup2(fd[i][0],0); } } } else { wait(&status); } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ return 0; }


Reply With Quote