Hi, I am attempting to create a program to make 3 child processes, the first child places 20 integers into the pipeline, the second child places another 2 integers into the pipeline and the thrid child reads all the data from the pipeline. i dunno who but thsi program has just gone totally wrong, could someone give me some advice on it please as my lectures are less that helpful.
Code:
#include<stdio.h>
#include<unistd.h>
int main()
{
int fd[3][2],i,j;
char odd[54];
char even[59];
char buffer[113];
char buffer2[113];
pipe(fd);
if(fork() == 0)
{
if(fork() == 0)
{
if(fork() == 0)
{
i = 0;
j = 0;
while(i < 20)
{
sprintf(even,"%d",j);
write(fd[2][1],even,sizeof(even));
i = i + 1;
j = i + 1;
}
exit(0);
}
i = 1;
j = 1;
while(i < 21)
{
sprintf(odd,"%d",j);
write(fd[1][1],odd,sizeof(odd));
i = i + 1;
j = i + 1;
}
exit(0);
}
read(fd[2][0],buffer,sizeof(buffer));
printf("%s\n",buffer);
read(fd[1][0],buffer2,sizeof(buffer2));
printf("%s\n",buffer2);
}
return 0;
}
Thanks Qui