Chinaunix首页 | 论坛 | 博客
  • 博客访问: 600744
  • 博文数量: 150
  • 博客积分: 1132
  • 博客等级: 少尉
  • 技术积分: 2067
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-11 16:46
文章分类

全部博文(150)

文章存档

2015年(15)

2014年(75)

2013年(4)

2012年(56)

分类: LINUX

2014-12-04 22:22:58

int pipe(int pipefd[2]);
用 pipe 创建一个管道。

1. 为什么在父子进程间使用管道需要关闭不必要的文件描述符?
An application that uses  pipe(2)  and fork(2) should use suitable close(2) calls to close unnecessary duplicate file descriptors;
this ensures that end-of-file and SIGPIPE/EPIPE are delivered when appropriate.

2. 管道的 buffer(PIPE_BUF):
Data written to the write end of the pipe is buffered by the kernel until it is read from the read end of the pipe.
如果 write 的字节数比 buffer 的大小还要大,会发生什么呢?
请参阅:man 7 pipe

3. FILE * popen(const char *command, const char *type);
功能:请帮手帮忙处理一下。
当 type == "r" :我给你提供数据(共用标准输入,通过标准输入提供),你帮我处理下,处理后的结果给我(通过从 stream 读);
当 type == "w" :我给你提供数据(通过写 stream ),你帮我处理下,处理后的结果给我(公用标准输出,直接写到标准输出)。
阅读(777) | 评论(0) | 转发(0) |
0

上一篇:参考文档

下一篇:shell 数组

给主人留下些什么吧!~~