[root@liumengli name_pipe]# mknod my_pipe p (创建命名管道,也可以通过系统调用来安装)
[root@liumengli name_pipe]# cat name_pipe_read.c
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "errno.h"
#include "fcntl.h"
int main() {
char buf[20];
int pipe_read;
int n_read;
pipe_read = open("./my_pipe", O_RDONLY, 0);
//打开管道,只读方式,注意与下面的区别,读者可以自己试试,可能参数有错,自己可以找到
//pipe_read = open("./my_pipe", O_RDONLY|O_NONBLOCK, 0);
if(pipe_read == -1) {
printf("error\n");
return 1;
}
memset(buf, 0, sizeof(buf));
n_read = read(pipe_read, buf, 20);
printf("You read %d chars\n", n_read);
printf("%s\n", buf);
return 0;
}
//读管道程序
[root@liumengli name_pipe]# cat name_pipe_read.c
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "errno.h"
#include "fcntl.h"
int main() {
char buf[20];
int pipe_read;
int n_read;
pipe_read = open("./my_pipe", O_RDONLY, 0);
if(pipe_read == -1) {
printf("error\n");
return 1;
}
memset(buf, 0, sizeof(buf));
n_read = read(pipe_read, buf, 20);
printf("You read %d chars\n", n_read);
printf("%s\n", buf);
return 0;
}
//写管道程序,2个进程通过my_pipe命名管道通信,如果对命名管道有兴趣,可以留言.
分享到:
相关推荐
进程间通讯(即:同机通讯)和数据交换有多种方式:消息、共享内存、匿名(命名)管道、邮槽、Windows套接字等多种技术。“共享内存”(shared memory)可以定义为对一个以上的进程是可见的内存或存在于多个进程的虚拟...
11.2.1 创建命名管道 300 11.2.2 管道监听 302 11.2.3 使用异步I/O进行读写 303 11.2.4 关闭管道实例 307 11.2.5 客户端 307 11.3 剪贴板 310 11.3.1 获取、设置剪贴板数据 310 11.3.2 监视剪贴板 ...
能够理解命名管道协议与t" "cp/ip协议的差别。能够登陆上sql server数据库服务器。 " "实验内容 " "1、启动sql server 服务。 " "2、打开sql server的企业管理器,连接上sql server服务器。展开左边 " "树状窗口的...
能够理解命名管道协议与t" "cp/ip协议的差别。能够登陆上sql server数据库服务器。 " "实验内容 " "1、启动sql server 服务。 " "2、打开sql server的企业管理器,连接上sql server服务器。展开左边 " "树状窗口的...
11.2.1 创建命名管道 300 11.2.2 管道监听 302 11.2.3 使用异步I/O进行读写 303 11.2.4 关闭管道实例 307 11.2.5 客户端 307 11.3 剪贴板 310 11.3.1 获取、设置剪贴板数据 310 11.3.2 监视剪贴板 ...
第1章 Windows应用程序开发入门..........................................................................................16 1.1 第一个实例程序...............................................................