接收端:

#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h> #define MKFIFO "./myfifo"
int main()
{
int ret;
ret = mkfifo (MKFIFO,);//创建有名管道文件
if((ret < )&&errno != EEXIST)
{
printf("error\n");
}
int fd = open (MKFIFO,O_RDWR);//打开文件
char buff[] = {};
ret = read (fd,buff,);//读取内容
int fd1 = open ("1.c",O_RDWR | O_CREAT | O_TRUNC,);
write (fd1,buff,ret);
printf ("recv %s\n",buff);
close (fd);
close (fd1);
return ;
}

发送端:

#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h> #define MKFIFO "./myfifo"
int main()
{
int ret;
ret = mkfifo(MKFIFO,);//创建管道文件
if ((ret < ) && errno != EEXIST)
{
perror("mkfifo");
return -;
}
int fd;
fd = open (MKFIFO,O_RDWR);//打开管道文件
char buff[] = {};
ret = read (,buff,);//从键盘输入
ret = write (fd,buff,ret);//写到文件
printf ("sent a msg:%s\n",buff);
close (fd);
return ;
}

最新文章

  1. 【转】 iOS9.2-iOS9.3.3越狱插件清单
  2. 经典Linq实例语句
  3. iOS开发-UINavigationBar透明设置
  4. 读javascript高级程序设计16-几条函数小技巧
  5. DWZ使用笔记
  6. linux中 ECShop的文件不能写
  7. TSSAO Temporal Screen-Space Ambient Occlusion (Unity3d 5 示例实现)
  8. Java学习笔记--StringTokenizer的使用
  9. 论山寨手机与Android联姻 【3】手机是怎样生产出来的
  10. jq 动态添加.active 实现导航效果
  11. CSS 换行问题white-space属性 window对象和global对象
  12. 【转】c++ 获取程序运行时间
  13. HTML之常用标签及属性
  14. js 数组、对象转json 以及 json转 数组、对象
  15. Android 和 JS交互方法初探
  16. winform NPOI excel 导出并选择保存文件路径
  17. Cocos2dx源码赏析(3)之事件分发
  18. C++学习---指针相关
  19. 【开发工具IDE】Eclipse 安装 Maven 的 m2eclipse 插件
  20. weex 初始化

热门文章

  1. 【C#复习总结】细说委托
  2. 开源后的.Net 如何选择使用
  3. vscode 缩进改为2空格
  4. Vue(二)基础
  5. 2018 Multi-University Training Contest 2
  6. CentOS 7.2 yum安装LAMP环境
  7. Day8 Python基础之遗漏知识点(六)
  8. 容器化-Docker介绍
  9. Linux下查看文件系统磁盘使用
  10. vue-lazyload简单使用