Write a program to create a child process in which child process displays number of line sent by parent process.
#include
#include
#include
#include
#include
main(int agrc,char *argv[])
{
int fd[2],pid,line=0,n;
char buffer[2048]="Milind Audichya\Dhruv Naik\Uzer Pathan\n",buffer2[1];
if(pipe(fd)==-1)
{
printf(" problem to create the pipe \n ");
exit(0);
}
else
{
pid=fork();
if(pid!=0)
{
printf("Perent Send Data To Chlid Data is:- %s ",buffer);
close(fd[0]);
write(fd[1],buffer,strlen(buffer));
close(fd[1]);
}
else
{
close(fd[1]);
printf("Chlid Process Read The Content send by the Perent.");
while((n=read(fd[0],buffer2,1)) == 1)
{
if(buffer2[0] == '\n')
{
line++;
}
}
printf("Number of line send by Perent:-%d",line);
close(fd[0]);
}
}
}
Comments
Post a Comment