I'm working on operating systems and in our work we aim to create a mini-shell. I'm having trouble with one of the steps related to commands with pipes, in this case I am testing the grep nomedoficheiro.c | wc
command.
Initially I count n=numero de comandos
, I create n-1 pipes
and I iterate over n child processes. I make dup2
of the pipe corresponding to the previous process with descriptor fileDescriptor [i - 1] [0] para
STDIN_FILENO e de seguida faço
dup2 do
fileDescriptor i para
STDIN_FILENO , posteriormente dou um
execvp 'and terminate the process. The parent process only updates the new command.
So far so good the idea is this, but I have a problem:
1: Linha 206:
When I dup2
my process ends without executing the remaining lines. What is this behavior about?
if (i != (number_commands - 1))
{
printf("child %s %d\n", commlist -> cmd, fd[i][1]);
dup2(fd[i][1], STDOUT_FILENO);
printf("child %s\n", commlist -> cmd);
close(fd[i][1]);
}