I'm trying to implement a multiple pipe for my shell in C.
All I have is a pipe function that pipe a | b but not a | b | c.
int c[2];
int returnv;
pid_t id;
pipe(c);
pid = fork()) == 0
if (pid)
{
dup2(c[1], 0);
close(p[1]);
close(p[1]);
execvp(array(0), array);
}
if ((pid = fork()) == 0)
{
dup2(p[0], 1);
close(p(0));
close(p[0]);
returnv = execvp(array[0], array);
}
close(p[1]);
wait(NULL);
wait(NULL);
wait(NULL);
return returnv;
And this is a second version:
int i = 0;
while (i < x)
{
pipe(c);
if ((pid = fork()) == 0)
{
dup2(t[i], 1);
if (i < 2)
dup2(p[0], 1);
close(p[1]);
r= execvp(cmd[i][0], cmd[i]);
}
wait(NULL);
close(p[0]);
i += 1;
t[i] = p[1];
How can I add the little something that will make this code manage multiple pipe please ? Thanks a lot in advance !