1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
//initializing the 10 multiple pipes
int fd[20];
for(int i=0;i<10;i++) {
if (pipe(fd+2*i) < 0)
{
write(STDERR_FILENO, "Pipe failed\n", 12);
exit(1);
}
}
//child process within the fork
case 0:
close(fd[2*child-2]);//close read end; of each pipe-fd[0] for child 1, fd[2] for child 2;
dup2(fd[2*child-1],2); //dup error stream to write end of pipe, fd[1] for child 1, fd[3] for child 2, etc.
close(fd[2*child-1]); //close write end*/
execlp("gcc","gcc",(filenameList[child]).c_str(), "-c", "-I/usr/include","-DPROGVERSION=1.0",(char *) 0);
_exit(0);
//the main parent thread - outside of the switch for the fork
for(int i=1;i<child;i++) {
close(fd[2*child-2]); //close write end
read(fd[2*child-1],buf,100);
cout<<buf;
}
|