#include<stdio.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<unistd.h>#include<stdlib.h>#include<string.h>intmain(){int ret =mkfifo("fifo.tmp",00400|00200);if(-1== ret){perror("fifo");exit(1);}char buf[32]={0};int fd =open("fifo.tmp",O_WRONLY);if(-1== fd){perror("open");exit(1);}while(1){scanf("%s",buf);
ret =write(fd,buf,strlen(buf));if(-1== ret){perror("write");}if(!strcmp(buf,"bye")){break;}memset(buf,0,sizeof(buf));}close(fd);return0;}
2.read
include <stdio.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<unistd.h>#include<stdlib.h>#include<string.h>intmain(){int fw =open("fifo.tmp",O_RDONLY);if(-1== fw){perror("open");exit(1);}char buf[32]={0};int ret;while(1){
ret =read(fw,buf,sizeof(buf));if(-1== ret){perror("read");exit(1);}if(!strcmp(buf,"bye")){break;}printf("%s\n",buf);memset(buf,0,sizeof(buf));}close(fw);return0;}