Linux下实现管道
来源:互联网 发布:mac 当前用户路径 编辑:程序博客网 时间:2024/05/16 17:39
运用管道知识做了单工通信的程序
pipeA.c代码如下:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
int main()
{
char name[20]="first.pipe";
char buff[256];
int r;
int fd;
//创建管道
r=mkfifo(name,0666);
if(-1==r)printf("mkfifo error%m\n"),exit(-1);
printf("mkfido %m\n");
//打开管道
fd=open(name,O_RDONLY);
if(-1==fd)printf("open error %m\n"),unlink(name),exit(-1);
printf("open %m\n");
while(1)
{
r=read(fd,buff,sizeof(buff)-1);
if(r>0)
{
buff[r]=0;
printf(">>>%s\n",buff);
}
}
return 0;
}
pipeB.c代码如下:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
int main()
{
char name[20]="first.pipe";
int r;
char buff[256];
int fd;
//打开管道
fd=open("/root/first.pipe",O_WRONLY);
if(-1 == fd) printf("open error:%m\n"),unlink(name),exit(-1);
printf("open %m\n");
while(1)
{
r=read(0,buff,256);
if(r>0)
{
write(fd,buff,r);
}
}
return 0;
}
运行成功,由于时间关系 图片就没发了
欢迎提问,做的不好的谢谢指出^-^....
- Linux下实现管道
- Linux下的管道pipe----管道容量和实现机制
- Linux下管道的实现机制
- linux下管道
- linux下管道通信
- linux下管道命令|
- linux下管道问题
- linux下的管道
- linux下使用管道实现一个简单的服务器/客户端
- linux下管道的容量以及实现机制
- linux下管道的容量以及实现机制
- Linux下利用命名管道实现简单的聊天室
- Linux下的管道容量及其实现机制
- Linux下的管道容量及其实现机制
- Linux管道实现机制
- 【Linux】中的管道实现
- linux 管道实现解析
- Linux下的有名管道(04)---使用一个管道实现数据的读写
- Android开发第一天--认识安卓文件
- kubernetes1.4.1安装教程
- 视频稳像(Video Stabilization)
- infrared
- 剑指offer--面试题44:扑克牌顺子
- Linux下实现管道
- rtems初始化过程分析
- android 的触摸事件的分发拦截机制分析
- Two Sum
- C语言判断闰年
- (八) 字符类设备注册
- 单例模式中的“饿汉”和“懒汉”的深入分析
- Sicily - 1137 河床 滑动窗口+优先队列 重庆一中高2018级竞赛班第十一次测试 2016.9.24 Problem 3
- 统计数据库中的无效网址