#include <myhead.h>
int main(int argc, const char *argv[])
{
mkfifo(“./f1”,0777);
mkfifo(“./f2”,0777);
pid_t cpid = fork();
if(0 < cpid)
{
int fdw = open(“./f1”,O_WRONLY);
int fdr = open(“./f2”,O_RDONLY);
char buf[128] = “”;
while(1)
{
bzero(buf,sizeof(buf));
printf(“父进程请输入>>>>>\n”);
scanf(“%s”,buf);
write(fdw,buf,sizeof(buf));
bzero(buf,sizeof(buf));
read(fdr,buf,sizeof(buf));
printf(“父进程接收打印:%s\n”,buf);文章来源:https://www.toymoban.com/news/detail-729368.html
}
close(fdw);
close(fdr);
}
if(0 == cpid)
{
int fdr = open("./f1",O_RDONLY);
int fdw = open("./f2",O_WRONLY);
char buf[128] = "";
while(1)
{
bzero(buf,sizeof(buf));
read(fdr,buf,sizeof(buf));
printf("子进程接收打印:%s\n",buf);
bzero(buf,sizeof(buf));
printf("子进程请输入>>>>>\n");
scanf("%s",buf);
write(fdw,buf,sizeof(buf));
}
close(fdw);
close(fdr);
}
return 0;
}文章来源地址https://www.toymoban.com/news/detail-729368.html
到了这里,关于10.3作业的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!