skyilyskyily.blog.chinaunix.net
skyily
全部博文(144)
2010年(16)
2009年(128)
Zane_Yu
tasteswe
zwrvvv
xiao888l
zimuqing
leilelei
Phyllis6
jonathan
denghai1
wbdwbd04
itTangze
lifj1234
18141908
AAABug
分类: C/C++
2009-04-11 09:53:54
#include <stdio.h> // ls -l | more #include <stdlib.h>#include <unistd.h>#include <sys/types.h>int main(void){ int fd[2]; pid_t pid; if(pipe(fd) < 0) { perror("pipe error!"); exit(0); } if((pid = fork()) < 0) { perror("fork error!"); exit(1); } else if(pid == 0) { close(fd[0]); //pipe read closed close(1); dup2(fd[1], 1); execl("/bin/ls", "ls", "-l", NULL); exit(1); } else { close(fd[1]); //pipe write closed close(0); dup2(fd[0], 0); execl("/bin/more", "more", NULL); exit(1); } return 0;}
上一篇:终端属性设置uart小实例
下一篇:自己封装的字符串切割函数
登录 注册