10.3作业

#include
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);

	}
	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;

}

你可能感兴趣的:(linux)