Linux管道编程实例
2014-10-01 20:38
344 查看
#include <unistd.h> #include <signal.h> #include <stdio.h> char parent[] = "a message from parrent"; char child[] = "a message from child"; main () { int chan1[2], chan2[2]; int pid; char buf[100]; pipe(chan1); pipe(chan2); pid=fork(); if(pid > 0) { close(chan1[0]); close(chan2[1]); write(chan1[1], parent, sizeof(parent)); close(chan1[1]); read(chan2[0],buf, 100); printf("%s\n", buf); close(chan2[0]); } else if(pid == 0) { close(chan1[1]); close(chan2[0]); read(chan1[0], buf, 100); printf("%s\n", buf); write(chan2[1], child, sizeof(child)); close(chan2[1]); close(chan1[0]); } }
相关文章推荐
- Linux管道编程实例
- Linux管道编程实例 http://blog.csdn.net/pcliuguangtao/article/details/6453743
- Linux管道编程实例
- Linux管道编程实例
- Linux管道编程实例
- Linux管道编程实例
- Linux管道编程实例
- Linux管道编程实例
- Linux管道编程实例
- Linux无名管道编程
- [编程实例]linux 设置网卡为混杂模式
- 尝试linux下c编程之管道
- [转]Linux下的管道编程技术:dup dup2 popen
- [编程实例]linux下的以太网简单网络流量分析
- Linux声音设备编程实例
- Linux下的管道编程技术-dup函数和dup2函数(网络资源)
- linux进程通信--管道(pipe)(含实例代码)
- Linux信号量编程实例
- Linux下的管道编程技术
- Linux有名管道编程