博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
管道编程之pipe
阅读量:2351 次
发布时间:2019-05-10

本文共 664 字,大约阅读时间需要 2 分钟。

pipe():创建一个新的匿名管道

例子中子进程必须等待父进程写入管道之后才能读。

thePipe[0]代表管道的输出,应用程序读它。

thePipe[1]代表管道的输入,应用程序写它。

#include 
#include
#include
#include
#define MAX_LINE 80int main(){ int thePipe[2], ret; char buf[MAX_LINE+1]; const char *testbuf = {"a test string."}; if(pipe(thePipe) == 0) { if(fork() == 0)   //子进程        { ret = read(thePipe[0], buf, MAX_LINE); buf[ret] = 0; printf("Child read %s\n", buf); } else              //父进程           { ret = write(thePipe[1], testbuf, strlen(testbuf)); ret = wait(NULL); } } }

转载地址:http://fshvb.baihongyu.com/

你可能感兴趣的文章
Eclipse修改Format不换行 详解
查看>>
Android导入工程提示 Invalid project description 详解
查看>>
Eclipse 历史纪录 详解
查看>>
Android StrictMode 详解
查看>>
Tomcat的优化
查看>>
Android Studio 出现 gradle DSL method not found: android() 错误
查看>>
Fragment 增加高德地图的 com.amap.api.maps.SupportMapFragment
查看>>
《你的投资机会在哪里》
查看>>
Bridge(桥接)模式
查看>>
生成器模式
查看>>
Android Studio 常用快捷键详解
查看>>
Cornerstone无法上传 .so 文件的问题
查看>>
Objective-C #pragma mark 详解
查看>>
Object-C 单例模式
查看>>
IOS 命名规范
查看>>
禁用sublime自动更新提示
查看>>
iOS Pch文件 详解
查看>>
Objective-C 获取控件 详解
查看>>
Objective-C 事件处理 详解
查看>>
IOS UIView 详解
查看>>