一个过程可以做
chdir("/to/some/where");
当从另一个外壳
mv /to/some/where /now/different/path/
第一个过程
print getcwd();
#prints /now/different/path/
是如何getcwd
实施的?(在最低级别,例如在内核级别,inode ...)。
我知道常见的(基于inode 的)文件系统是如何工作的,例如包含目录的内容(条目名称和相应的inode 编号)。
编辑
可能问题是模糊的 - 试图完善它。一种可能的情况(据我们所知)
- 内核知道
CWD
给定进程(和他的线程)的inode - 例如inode number1000
- 读取 inode(获取需要读取的块)
- 读取相应的块(例如打开目录)
- 读取目录条目(条目名称和 inode 编号)
- 获取
..
父目录(例如900
)的 inode 号和.
(当前目录)的 inode 号 - 读取获取的父目录的内容
- 上
name
一个目录的(对于 inode1000
) - 父目录的inode号
- 继续
5.
- 直到到达根 inode。
也就是说,getcwd
对于
/some/very/very/very/deep/directory/level
需要更多原始 IO 操作(需要读取更多目录条目)
/tmp
整体getcwd
是由两个读数完成的?
这个对吗?还是完全以另一种方式完成?