I've also added wait() in parents' code:
Code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#define MAXLEN 1000 /* Maksymalna dlugosc input_pipeu */
#define BUFSIZE 20 /* Rozmiar uzywanych buforow */
int main()
{
int i,
j,
rec,
status,
fd[2];
char tmp,
input_pipe[MAXLEN],
command[MAXLEN],
buf[BUFSIZE];
i = 0;
scanf("%c", &tmp);
while(tmp != '\n')
{
input_pipe[i] = tmp;
i++;
scanf("%c", &tmp);
}
input_pipe[i] = 0;
pipe(fd);
memset(command, 0, MAXLEN);
j = 0;
for(i = 0; i < strlen(input_pipe); i++)
{
printf("%d\n", i);
if(input_pipe[i] != '|')
{
command[j] = input_pipe[i];
j++;
}
else
{
command[j] = 0;
/* printf("::%s\n", command); */
if(fork() == 0)
{
if(dup2(fd[0], 0) == -1)
printf("dup2() error1\n");
if(dup2(fd[1], 1) == -1)
printf("dup2() error2\n");
system(command);
exit(5);
}
else
{
wait(&status);
memset(command, 0, MAXLEN);
j = 0;
}
}
}
if(fork() == 0)
{
dup2(fd[0], 0);
dup2(fd[1], 1);
system(command);
exit(6);
}
else
{
wait(&status);
while((rec = read(fd[0], buf, BUFSIZE)) > 0)
write(1, buf, rec);
}
return 0;
}
But it's still the same :/