读
#include<string.h>
#include<unistd.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
int main()
{
int ret;
int fd;
ret=mkfifo("my_fifo",0666);
if(ret!=0){
perror("mkfifo the fail");
exit(1);
}
fd=open("myfifo",O_WRNOLY|O_NONBLOCK);
if(fd<0){
perror("open the fail");
exit(1);
}
char send[100]="hello BaoBei";
write(fd,send,sizeof(send));
printf("write to my_fifo buf=%s\n",send);
while(1);
return 0;
}
写
#include<unistd.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<string.h>
#include<fcntl.h>
int main()
{
int ret;
int fd;
ret=mkfifo("my_fifo",0666);
if(ret!=0){
perror("create my_fifo fail");
exit(1);
}
fd=open("my_fifo",O_RDONLY|O_NONBLOCK);
if(fd<0){
perror("open the my_fifo fail");
exit(1);
}
while(1){
char recv[100]={0};
read(fd,recv,sizeof(recv));
printf("read from my_fifo buf=[%s]\n",recv);
sleep(1);
}
return 0;
}