小白笔记----pipe管道(2)(dup的用法)
2015-10-24 17:06
417 查看
大概理解了dup的意思,mark一下
/*-------2015/10/24----------*/ #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<unistd.h> #include<string.h> void pipe_read(int p) { char m[100] ; read(p,m,100); printf("that: is what we get:%s\n",m); } void pipe_write(int p) { char m[100] = "aaron"; write(p,m,strlen(m)+1); } main(int agrc,char **argv[],char * environ) { int p; pid_t pid; int pipefd[2]; p = pipe(pipefd); pid = fork(); if(pid < 0){ printf("error\n"); } if(pid == 0 ) { printf("i am a child process\n"); close(0); dup(pipefd[0]); close(pipefd[0]); close(pipefd[1]); pipe_read(0); execv("list2",NULL);// The exec() family of functions replaces the current process image witha new process image. exit(0); } if(pid > 0) { printf("i am a parent process\n"); close(0); dup(pipefd[1]); close(pipefd[1]); close(pipefd[0]); pipe_write(0); wait(NULL); exit(0); } return 0; }
相关文章推荐
- Servlet的学习之Session(4)
- opencv学习笔记(十五)——图像融合
- 小心呀! 互联网公司就是用这 5 招, 干掉了你的公司
- 项管44项自测的PPTX动画
- Java-HttpSession
- Java-HttpSession
- hdu 1072 Nightmare(BFS法和DFS法)
- 获取鼠标相对某个div的偏移量
- Alcatraz不显示Load Bundle解决办法
- 如何用Maven创建web项目(具体步骤)
- Java-HttpSession
- 向JavaScript的数组中添加元素的方法小结
- KeyTool 使用
- abstract class和interface有什么区别?
- ubuntu 修改ntfs文件系统的权限
- 手动导入第三方工程/类库
- _pActualRawDllMain cannot be in a R/W section
- 【计算机视觉】OpenCV人脸识别facerec源码分析2——LBPH概述
- 【算法,算法】排序
- Python3.5环境安装及使用 Speech问题解决