#include<stdio.h>
#include<string.h>
#include<myhead.h>
int main(int argc, const char *argv[])
{
pid_t pid;
pid=fork();
if(pid>0)
{
int send;
send = open("./my_fifo1",O_WRONLY);
if(send==-1)
{
perror("open send");
return -1;
}
char buff[1024];
char arr[10]="quit\n";
while(1)
{
memset(buff,'\0',sizeof(buff));
int len=read(0,buff,sizeof(buff));
//write(send,buff,len);
if(strcmp(buff,arr)==0)
{
break;
}
//sleep(1);
write(send,buff,len);
}
close(send);
}
else if(pid==0)
{
int rev;
rev=open("./my_fifo2",O_RDONLY);
if(rev==-1)
{
perror("open rev");
return -1;
}
char buff1[1024];
char arr[10]="quit\n";
while(1)
{
memset(buff1,'\0',sizeof(buff1));
int len1=read(rev,buff1,sizeof(buff1));
//write(1,buff1,len1);
if(strcmp(buff1,arr)==0)
{
break;
}
//sleep(1);
write(1,buff1,len1);
}
close(rev);
}
else
{
perror("fork");
return -1;
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<myhead.h>
int main(int argc, const char *argv[])
{
pid_t pid;
pid=fork();
if(pid>0)
{
int send;
send = open("./my_fifo2",O_WRONLY);
if(send==-1)
{
perror("open send");
return -1;
}
char buff[1024];
char brr[10]="quit\n";
while(1)
{
memset(buff,'\0',sizeof(buff));
int len=read(0,buff,sizeof(buff));
//write(send,buff,len);
if(strcmp(buff,brr)==0)
{
break;
}
//sleep(1);
write(send,buff,len);
}
close(send);
}
else if(pid==0)
{
int rev;
rev=open("./my_fifo1",O_RDONLY);
if(rev==-1)
{
perror("open rev");
return -1;
}
char buff1[1024];
char brr[10]="quit\n";
while(1)
{
memset(buff1,'\0',sizeof(buff1));
int len1=read(rev,buff1,sizeof(buff1));
// write(1,buff1,len1);
if(strcmp(buff1,brr)==0)
{
break;
}
//sleep(1);
write(1,buff1,len1);
}
close(rev);
}
else
{
perror("fork");
return -1;
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<myhead.h>
int main(int argc, const char *argv[])
{
if(mkfifo("./my_fifo1",0664)==-1)
{
perror("mkfifo");
return -1;
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<myhead.h>
int main(int argc, const char *argv[])
{
if(mkfifo("./my_fifo2",0664)==-1)
{
perror("mkfifo");
return -1;
}
return 0;
}