pipe用法
来源:互联网 发布:java代理模式的好处 编辑:程序博客网 时间:2024/06/08 13:52
pipe()函数例子:
#include<unistd.h>
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
int main(void)
{
int ret = -1;
int nbytes;
pid_t pid;
char buf[] = "pipe test";
char rdbuf[80] ;
int fd[2];
int *write_fd = &fd[1];/*写描述符*/
int *read_fd = &fd[0];
ret = pipe(fd);/*建立管道*/
if(ret<0)
{
printf("管道建立失败\n");
return -1;
}
pid = fork();/*创建进程*/
if(pid==-1)
{
printf("进程建立失败\n");
return -1;
}
if(pid ==0)/*子进程*/
{
close(*read_fd);/*关闭读*/
ret = write(*write_fd,buf,strlen(buf));/*写入字符*/
return 0;
}
else
{
close(*write_fd);/*关闭写*/
memset(rdbuf,0,sizeof(rdbuf));
nbytes = read(*read_fd,rdbuf,sizeof(rdbuf));/*读取字符*/
printf("revice%ddatas:%s \n",nbytes,rdbuf);
}
return 0;
}
阅读全文
0 0
- pipe用法
- pipe fd_set 用法
- pipe 命令用法
- pipe row的用法
- python pipe模块用法
- multiprocessing.Pipe()的用法
- pipe()
- pipe
- pipe
- pipe
- pipe
- PIPE
- pipe
- pipe
- pipe
- pipe
- pipe
- pipe
- 静态链表的基本操作实现
- 【makefile】一起写makefile(八) --隐含规则
- QPushButton的一些stylesheet设置
- Excel在统计分析中的应用—第五章—概率分布及概率分布图-Part10-二项分布的应用
- Linux中Samba配置
- pipe用法
- [Android学习笔记] Overlaying Action Bar
- Node Client code
- 实验报告_ASE_lab4
- leetcode 77
- Thinking in Java 之 多线程 2
- 简单linux启动过程
- scala 简介
- 关于springboot过滤器处理request参数问题