一个简单的无名管道示例
来源:互联网 发布:天尚网络机顶盒官网 编辑:程序博客网 时间:2024/05/21 00:20
Linux中,函数
int pipe(int fds[2]);
创建一个无名管道,产生了两个 文件描述符,存放在数组 fds 中,其中 fds[0] 表示读端,fds[1] 表示写端;成功返回0,失败返回-1;
示例:创建一个无名管道,fork一个子进程,父进程写,子进程读。
#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <unistd.h>int main(void){ int fds[2]; if(pipe(fds)){ perror("pipe"); exit(1); } pid_t pid; char buf[80]; if((pid = fork()) < 0){ perror("fork"); exit(1); } else if(pid > 0){ printf("in father progress\n"); char s[] = "Hello~message from father progress~"; write(fds[1], s, sizeof(s)); close(fds[0]); close(fds[1]); } else{ printf("in children progress\n"); read(fds[0], buf, 80); printf("%s\n", buf); close(fds[0]); close(fds[1]); } waitpid(pid, NULL, 0); return 0;}
- 一个简单的无名管道示例
- 1.5 简单的无名管道使用
- Linux--无名管道pipe示例
- 无名管道的用法
- 无名管道的使用
- 无名管道的通信
- ipc(一)无名管道示例
- 无名管道pipe的读写
- 无名管道的C++封装
- 无名管道的C++封装
- Linux下的无名管道
- 无名管道的父子通信
- 无名管道pipe的使用
- 无名管道pipe的使用
- 无名管道pipe的使用
- 有名管道和无名管道的区别
- 有名管道和无名管道的区别
- 有名管道和无名管道的区别
- Proper Screencasting on Linux
- ssh hibernate struts spring 工作原理及为什么要用
- CSS学习——文本属性
- PyQt4 QLineEdit 使用方法
- AS3_MVC解析
- 一个简单的无名管道示例
- 任正非:中国没有创新土壤 不开放就是死亡
- C++模板元编程(1)
- WCF系列:服务的发布和使用
- csharp: winform using Microsoft.Ink(Tablet PC API) create Signature image
- Auto Insert New Hires as PS Users
- 比较详细的Mencoder命令行使用
- PyQt4学习资料
- C++/C#中堆栈、对象内存模型、深浅拷贝、Array.Clone方法