进程间通讯:有名管道FIFO
2024-09-09 03:27:02
接收端:
#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 ;
}
最新文章
- 【转】 iOS9.2-iOS9.3.3越狱插件清单
- 经典Linq实例语句
- iOS开发-UINavigationBar透明设置
- 读javascript高级程序设计16-几条函数小技巧
- DWZ使用笔记
- linux中 ECShop的文件不能写
- TSSAO Temporal Screen-Space Ambient Occlusion (Unity3d 5 示例实现)
- Java学习笔记--StringTokenizer的使用
- 论山寨手机与Android联姻 【3】手机是怎样生产出来的
- jq 动态添加.active 实现导航效果
- CSS 换行问题white-space属性 window对象和global对象
- 【转】c++ 获取程序运行时间
- HTML之常用标签及属性
- js 数组、对象转json 以及 json转 数组、对象
- Android 和 JS交互方法初探
- winform NPOI excel 导出并选择保存文件路径
- Cocos2dx源码赏析(3)之事件分发
- C++学习---指针相关
- 【开发工具IDE】Eclipse 安装 Maven 的 m2eclipse 插件
- weex 初始化