进程间的通信----有名管道fifo
来源:互联网 发布:清朝灭亡 知乎 编辑:程序博客网 时间:2024/05/16 01:01
write端:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
int main(int argc, const char *argv[])
{
if(access("./myfifo",F_OK) < 0)
{
if(mkfifo("./myfifo",0644) < 0)
{
perror("mkfifo fail\n");
return -1;
}
}
int fd;
char buff[128] = "\0";
fd = open("./myfifo",O_RDWR,0644);
while(1)
{
printf("请输入信息:\n");
scanf("%s",buff);
if(write(fd,buff,sizeof(buff)) < 0);
{
perror("write fail\n");
return -1;
}
if(strcmp(buff,"quit") == 0)
{
sleep(1);
printf("以结束写入信息!\n");
return 0;
}
memset(buff,0,sizeof(buff));
}
return 0;
}
read端:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
int main(int argc, const char *argv[])
{
if(access("./myfifo",F_OK) < 0)
{
if(mkfifo("./myfifo",0644) < 0)
{
perror("mkfifo fail\n");
return -1;
}
}
int fd;
char buff[128] = "\0";
fd = open("./myfifo",O_RDWR,0644);
while(1)
{
printf("读到的信息:");
if(read(fd,buff,sizeof(buff)) < 0)
{
perror("read fail\n");
return -1;
}
printf("%s\n",buff);
if(strcmp(buff,"quit") == 0)
{
printf("准备退出!\n");
return 0;
}
}
return 0;
}
- 进程间的通信----有名管道fifo
- 进程间通信______有名管道(FIFO)
- 进程通信-有名管道FIFO
- Linux--进程间通信(管道及有名管道FIFO)
- Linux--进程间通信(管道及有名管道FIFO)
- Linux--进程间通信(管道及有名管道FIFO)
- 2、进程间通信-FIFO(有名管道)
- 【七】 进程间通信——(FIFO)有名管道
- 进程间通信---------有名管道(named pipe/FIFO)
- linux进程间通信-有名管道(FIFO)
- linux进程间通信-有名管道(FIFO)
- Linux进程间通信二--有名管道FIFO
- linux编程---进程间通信---FIFO---有名管道
- 进程间通信——有名管道(FIFO)
- Linux进程间通信——有名管道 FIFO 详解
- linux进程通信----FIFO(有名管道)
- Linux进程间的通信——有名管道fifo与守护进程deamon
- Linux环境进程间通信之有名管道(FIFO)的注意事项
- 3*3的矩阵转置
- HDU-1171 Big Event in HDU (多重背包)
- 设计模式---装饰模式
- Eclipse安装svn插件的几种方式
- 2.Spark Streaming:基本工作原理
- 进程间的通信----有名管道fifo
- 使用Python绘制雷达图
- 卡尔曼滤波和维纳滤波
- ubuntu繁体字简体字切换
- 用Leangoo管理你的项目
- python入门第一步,python怎样入门
- 从零开发B/S机架应用程序(四)-TCP
- Spring注入复杂类型属性
- 文章标题