#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#define BUFES PIPE_BUF
int main(int argc, char **argv)
{
int fd;
int len;
char buf[BUFES];
mode_t mode =0666;
fd= open("fifo1",O_RDONLY);
if (fd<0){
perror("failed");
exit(1);
}
while(1)
{
if((len =read(fd,buf,BUFES))>0)
{
printf("%s ",buf);
}
}
close(fd);
exit(0);
return 0;
}
本文介绍如何使用C语言通过打开FIFO管道并进行读取操作来实现数据的简单传输过程。
1182

被折叠的 条评论
为什么被折叠?



