#include <myhead.h>
#define FIFO1 "./f_fifo"
#define FIFO2 "./f_pipo"
int main(int argc, const char *argv[])
{
mkfifo(FIFO1,0664);
mkfifo(FIFO2,0664);
pid_t pid1=fork();
if(pid1>0)
{
close(creat(FIFO1,0664));
int fd1=open(FIFO1,O_RDONLY);
char buff[1024];
write(fd1,buff,sizeof(buff));
close(creat(FIFO2,0664));
int fd2=open(FIFO2,O_WRONLY);
char buffer[1024];
read(fd2,buffer,sizeof(buffer));
printf("父进程从子进程接收的%s\n",buffer);
close(fd1);
close(fd2);
}
else if(pid1==0)
{
close(creat(FIFO2,0664));
int fd2=open(FIFO2,O_RDONLY);
char buff[1024];
read(fd2,buff,sizeof(buff));
printf("子进程从父进程收到的消息%s\n",buff);
close(creat(FIFO1,0664));
int fd1=open(FIFO1,O_WRONLY);
char buffer[1024];
write(fd1,buffer,sizeof(buffer));
close(fd1);
close(fd2);
}
else
{
perror("fork");
return -1;
}
return 0;
}