如何解决管道的其他过程在哪里?
我研究了管道的概念,并且我理解了一切。我找到并运行了以下代码,这些代码演示了管道的用法。但是,没有fork()函数来创建另一个进程,并且代码的执行仅创建一个进程。其他过程在哪里?非常感谢!
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#define MSGSIZE 16
char* msg1 = "hello,world #1";
char* msg2 = "hello,world #2";
char* msg3 = "hello,world #3";
int main() {
char inbuf[MSGSIZE];
int p[2],i;
if (pipe(p) < 0)
exit(1);
/* continued */
/* write pipe */
write(p[1],msg1,MSGSIZE);
write(p[1],msg2,msg3,MSGSIZE);
for (i = 0; i < 3; i++) {
/* read pipe */
read(p[0],inbuf,MSGSIZE);
printf("%s\n",inbuf); }
return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。