Hi,
I am working in pipes.I have created a pipe then create a child process by fork.Child process is wrinting into the pipe and
then parent read frm the pipe and displayed it.This code is working alright
int main()
{
int fd[2];
int fd2[2];
int pp,pp2;
int status;
char *string = "This is my first Pipe creation",buff[1024];
int p_id;
pp=pipe(fd);
if(pp<0)
printf("Pipe creation failed");
else
{
p_id = fork();
if(p_id < 0)
printf("Fork Failed");
if(p_id == 0)
{
close(fd[0]);
write(fd[1],string,strlen(string));
read(fd2[0],buff2,strlen(string2));
exit(7);
}
else
{
wait(&status);
close(fd[1]);
read(fd[0],buff,strlen(string));
printf("BUFFER : ");
printf(buff);
}
}
return 0;
}
What i want is to create a full duplex pipe where both child and parent process can read and write.For tht im creating two
pipes.When i executes the below program with two pipes it get stuck on the command line.Plz tell me where im goin wrong in
the below code.
int main()
{
int fd[2];
int fd2[2];
int pp,pp2;
int status;
char *string = "This is my first Pipe creation",buff[1024];
char *string2 = "Parent writing",buff2[1024];
int p_id;
pp=pipe(fd);
pp2=pipe(fd2);
if(pp<0)
printf("Pipe creation failed");
else
{
p_id = fork();
if(p_id < 0)
printf("Fork Failed");
if(p_id == 0)
{
close(fd[0]);
write(fd[1],string,strlen(string));
read(fd2[0],buff2,strlen(string2));
printf("buff2");
exit(7);
}
else
{
wait(&status);
close(fd[1]);
read(fd[0],buff,strlen(string));
printf("BUFFER : ");
printf(buff);
write(fd2[1],string2,strlen(string2));
}
}
return 0;
}
I am working in pipes.I have created a pipe then create a child process by fork.Child process is wrinting into the pipe and
then parent read frm the pipe and displayed it.This code is working alright
int main()
{
int fd[2];
int fd2[2];
int pp,pp2;
int status;
char *string = "This is my first Pipe creation",buff[1024];
int p_id;
pp=pipe(fd);
if(pp<0)
printf("Pipe creation failed");
else
{
p_id = fork();
if(p_id < 0)
printf("Fork Failed");
if(p_id == 0)
{
close(fd[0]);
write(fd[1],string,strlen(string));
read(fd2[0],buff2,strlen(string2));
exit(7);
}
else
{
wait(&status);
close(fd[1]);
read(fd[0],buff,strlen(string));
printf("BUFFER : ");
printf(buff);
}
}
return 0;
}
What i want is to create a full duplex pipe where both child and parent process can read and write.For tht im creating two
pipes.When i executes the below program with two pipes it get stuck on the command line.Plz tell me where im goin wrong in
the below code.
int main()
{
int fd[2];
int fd2[2];
int pp,pp2;
int status;
char *string = "This is my first Pipe creation",buff[1024];
char *string2 = "Parent writing",buff2[1024];
int p_id;
pp=pipe(fd);
pp2=pipe(fd2);
if(pp<0)
printf("Pipe creation failed");
else
{
p_id = fork();
if(p_id < 0)
printf("Fork Failed");
if(p_id == 0)
{
close(fd[0]);
write(fd[1],string,strlen(string));
read(fd2[0],buff2,strlen(string2));
printf("buff2");
exit(7);
}
else
{
wait(&status);
close(fd[1]);
read(fd[0],buff,strlen(string));
printf("BUFFER : ");
printf(buff);
write(fd2[1],string2,strlen(string2));
}
}
return 0;
}