完成
6.s081lab1 后对pipeline,file descriptor有了一定了解,做个笔记
pipeline (pipe)
A
pipeis a small kernel buffer exposed to processes as a pair of file descriptors, one for reading and one for writing. Writing data to one end of the pipe makes that data available for reading from the other end of the pipe. Pipes provide a way for processes to communicate.
使用:
| |
file descriptor (fd)
fd是对广义上的UNIX file进行引用的一层抽象,这层抽象使得在操作regular file, device, pipeline 等文件时,表面上一致,操作起来简单,(都可使用read(int fd,..); write(int fd,...)等透过fd的API), 但实现上,不同类型的文件大不相同.
几个重要的fd特性
- 总是自动打开3个
fd, 0=stdin, 1=stdout, 2=stderr - 总是选取最小的
fd
| |
file descriptor table由进程维护,即进程间fd互不影响
以下代码来自
lab 1实验primes, 实现了下图所示的埃氏筛法为摆脱
xv6对fd数目的限制,每个子进程都对管道传入的fd进行了多次重定向, 但在子进程改变fd并不影响父进程,程序能正常执行
| |
- 经由
fork和dup得到,的对同一文件的fd, 它们共享偏移
fork
| |
为摆脱