匿名管道在兄弟进程的应用
来源:互联网 发布:开淘宝店前期准备 编辑:程序博客网 时间:2024/04/30 06:33
#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <limits.h>#include <fcntl.h>#include <sys/types.h>#define BUFSZ PIPE_BUFvoid err_quit(char * msg){perror( msg );exit(1);}int main ( void ) {int fd[2];char buf[BUFSZ];/* 缓冲区 */pid_t pid;int len;if ( (pipe(fd)) < 0 )/*创建管道*/err_quit( "pipe" );if ( (pid = fork()) < 0 )/*创建第一个子进程*/err_quit("fork");else if ( pid == 0 ){/*子进程中*/close ( fd[0] );/*关闭不使用的文件描述符*/write(fd[1], "hello brother!\n", 15 );/*发送消息*/exit(0);}if ( (pid = fork()) < 0 )/*创建第二个子进程*/err_quit("fork");else if ( pid > 0 ){/*父进程中*/close ( fd[0] );close ( fd[1] );exit ( 0 );}else {/*子进程中*/close ( fd[1] );/*关闭不使用的文件描述符*/len = read (fd[0], buf, BUFSZ );/*读取消息*/write(STDOUT_FILENO, buf, len);exit(0);}}
0 0
- 匿名管道在兄弟进程的应用
- linux匿名管道的应用
- 通过匿名管道在进程间双向通信
- 通过匿名管道在进程间双向通信
- Linux进程间通信::读写特性和匿名管道的应用(协同进程实例)
- 匿名管道--进程间的通信
- 进程通信-匿名管道
- 进程通信 - 匿名管道
- C#使用匿名管道在本地进程之间进行通信
- 进程通信系列-匿名管道
- 匿名管道与子进程
- 进程间通信-匿名管道
- 进程间通信 - 匿名管道
- 进程通信_匿名管道
- 进程间通信匿名管道
- 【Linux】 进程通信--匿名管道
- 进程间通讯---匿名管道
- 进程间通信-匿名管道
- Maven 使用Nexus创建私服
- 美国窃听技术“十八般武艺”欲监控全球
- webservice 短信发送(empp64.dll)
- 【黑马程序员】Java学习笔记--IO流
- Struts2中访问web元素的四种方式(访问requst、session、application)
- 匿名管道在兄弟进程的应用
- TXT转换成pdf出现乱码怎么办
- bootstrap 注意点
- PHP 常用函数
- 待解决:android 中德数据容器
- iOS 核心动画高级技巧
- SQL语句修改表字段及属性
- js 闭包
- window.location.Reload()和window.location.href 区别