int n,fd[2];
pid_t pid;
char line[101];
if(pipe(fd)< 0)
{
printf("pipe error\n");exit(1);
}
if((pid=fork()) < 0)
{
printf("fork error\n"); exit(1);
}
else if (pid > 0)
{
close(fd[0]);
int n;
while((n=read(STDIN_FILENO,line,100))>0)
{
write(fd[1],line,n);
}
}
else{
close(fd[1]);
int n;
while((n=read(fd[0],line,100))>0)
{
line[n]='\0';
printf("%s",line);
}
}
exit(0);
}
C-pipe
原创
©著作权归作者所有:来自51CTO博客作者bio_tt的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:C-sys/time
下一篇: C小知识
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C++实现进程通信(管道pipe)
本节内容1、功能简介1.1 匿名管道1.2 命名管道2、匿名管道3、命名管道3.1 注意事项3.2 服务器3.2 客户端后记1、功能简介管道
c++ 网络 管道 网络通信 windows -
Cypher语言 APOC函数 c语言pipe函数
pipe我们用中文叫做管道。 以下讲解均是基于Linux为环境:函数简介 所需头文件 #include<unistd.h> 函数原型 int pipe(int fd[2]) 函数传入值 fd[2]:管道的两个文件描述符,之后就是可以直接操作这两
Cypher语言 APOC函数 c/c++ python 操作系统 数据