Featured image of post 北航OS Lab6 管道与SHELL

北航OS Lab6 管道与SHELL

实验报告

实验报告

思考题

Thinking 6.1

只需对父子进程的读写端口与管道行为等进行对调

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
switch(fork()) {
	case -1:
	break;

	case 0: /*子进程-作为管道的写者*/
	close(fildes[0]); /*关闭不用的读端*/
	write(fildes[1],"Helloworld\n",12); /*向管道中写数据*/
	close(fildes[1]); /*写入结束,关闭写端*/
	exit(EXIT_SUCCESS);

	default: /*父进程-作为管道的读者*/
	close(fildes[1]); /*关闭不用的写端*/
	read(fildes[0],buf, 100); /*从管道中读数据*/
	printf("father-processread:%s",buf); /*打印读到的数据*/
	close(fildes[0]); /*读取结束,关闭读端*/
	exit(EXIT_SUCCESS);
	}

Thinking 6.2

难点分析

实验体会

comments powered by Disqus
Easy Life and Easy Learning
使用 Hugo 构建
主题 StackJimmy 设计