#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#define BUFFER_SIZE 1024
int main(int argc,char **argv)
{
int fd;
if(argc<2)
{
fprintf(stdout,"Usagea:%s<filename>\n",argv[0]);
exit(-1);
}
if((fd=open(argv[1],O_RDONLY))<0)
{
fprintf(stderr,"open fifo %s for reading failed:%s\n",argv[1],strerror(errno));
exit(-1);
}
fprintf(stdout,"open fifo %s for reading successed.\n",argv[0]);
char buffer[BUFFER_SIZE]="0";
ssize_t n;
while(1)
{
if((n=read(fd,buffer,BUFFER_SIZE))<0)
{
fprintf(stderr,"read failed on %s:%s\n",argv[1],strerror(errno));
exit(EXIT_FAILURE);
}
else if(0==n)
{
fprintf(stderr,"peer closed fifo.\n");
break;
}
else
{
fprintf(stdout,"read%d bytes from fifo:%s\n",n,buffer);
}
}
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
进程间通信之有名管道(fifo) 注意: 如果只打开有名管道的一端 则系统将暂时阻塞打开进程 直到有另一个进程打开该管道的另一端 当前进程才会继续执行 七种进程间通信方式: 一 无名管道( pipe ) 二 有名管道( fifo ) 三 共享内存 shared memory 四 信号 sinal 五 消息队列 message queue ) 六 信号量 semophore 七 套接字 socket 以上七种进程间通信的完整代码 皆可以在我的资源列表中获取下载: 资源列表:http: download csdn net user qiulanzhu">进程间通信之有名管道(fifo) 注意: 如果只打开有名管道的一端 则系统将暂时阻塞打开进程 直到有另一个进程打开该管道的另一端 当前进程才会继续执行 七种进程间通信方式: 一 无名管道( pipe ) 二 有名管道( f [更多]
资源推荐
资源详情
资源评论
收起资源包目录
fifo.rar (3个子文件)
write_fifo.c 762B
read_fifo.c 913B
create_fifo.c 349B
共 3 条
- 1
资源评论
晓石头
- 粉丝: 34
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功