mkfifo 创建管道IO 进程间交互
来源:互联网 发布:大禹 知乎 编辑:程序博客网 时间:2024/05/20 00:49
mkfifo 创建管道IO
一.程序:
1) 接收程序:
[user:lib_hdmanage] cat example/rec.cpp
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#define FIFO "disk_switch"
int main()
{
char buffer[80];
int fd = 0;
unlink(FIFO);
mkfifo(FIFO,0666);
while(1)
{
if((fd = open (FIFO,O_RDONLY)) < 0) //阻塞在open函数.等发送端的open函数 ,两个open函数建立连通后才会解除阻塞.
{
printf("open error!\n");
return -1;
}
read(fd,buffer,80);
printf("%s",buffer);
close(fd);
fd = 0;
sleep(1);
}
return 0;
}
[user:lib_hdmanage]
2) 发送程序:
[user:lib_hdmanage] cat example/send.cpp
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#define FIFO "disk_switch"
int main()
{
int fd = 0;
// unlink(FIFO);
// mkfifo(FIFO,0666);
char s[] = "hello!\n";
if((fd = open (FIFO,O_WRONLY)) < 0)
{
printf("open error!\n");
return -1;
}
write(fd,s,sizeof(s));
close(fd);
fd = 0;
return 0;
}
[user:lib_hdmanage]
二.运行结果:
1) 运行:
第一终端:[user:lib_hdmanage] ./example/rec.i386.elf
第二终端:[[user:lib_hdmanage] ./example/send.i386.elf
2)显示:
第一终端:hello!
- mkfifo 创建管道IO 进程间交互
- 【linux】mkfifo 命令创建命名管道实现进程之间通信
- mkfifo函数创建有名管道
- Linux下进程间通信:命名管道-mkfifo
- Linux下进程间通信:命名管道-mkfifo
- Linux c 管道文件-进程间的通信 mkfifo、pipe
- mkfifo命令不好使时创建命名管道
- 管道(pipe、mkfifo)
- shell mkfifo 阻塞式管道
- Linux_ mkfifo 命名管道 操作
- 进程间通信-创建管道实现机制
- linux 管道创建进程
- Linux系统中mkfifo创建管道后,调用open打开失败,不知道错在哪儿
- linux进程间通信程-pipe、mkfifo、…
- 管道的使用——mkfifo
- Linux_ mkfifo 命名管道 操作demo
- System.IO之使用管道在进程间通信 (System.IO.Pipes使用)
- System.IO之使用管道在进程间通信 (System.IO.Pipes使用)
- 11 ScrollView
- DAO调用Oracle带自定义类型的存储过程.
- 根据几种典型的WEB服务器应用的特点做出的系统架构建议
- 12 ListView
- HDU1159——Common Subsequence
- mkfifo 创建管道IO 进程间交互
- poj-2516-Minimum Cost-最小费用最大流
- 13 Dialog
- 算法-java版算法竞赛入门解题代码-第3章习题
- linux安装jdk1.7
- 关于log4j:WARN No appenders could be found for logger (org.apache.commons.digest错误
- GCC常用的编制指令
- 14 AutoCompleteTextView
- Ubuntu下安装usbview