
进程是通过文件描述符(file descriptor,fd)来访问文件的,每个进程最多能同时使用NR_OPEN个文件描述符,这个值在include/linux/limits.h中定义为1024。每一个进程用一个打开文件表files_struct来描述进程的文件描述符使用情况。每一个文件都有一个文件指针。windows并行文件系统
进程的task_struct中有文件系统相关的数据成员:
结构fs_struct给出了与进程相关的文件系统的信息,比如进程自己的当前工作目录,它的根目录等,这个结构的定义为:
---------------------------------------------------------------------
include/linux/fs_struct.h
struct fs_struct {
int users;
rwlock_t lock; /* 用于表中字段的读/写自旋锁 */
int umask; /* 当打开文件设置文件权限时所使用的位掩码 */
int in_exec;
struct path root, pwd;
};
---------------------------------------------------------------------
其中path结构的root和pwd两个成员分别描述了进程最常用到的两个目录的信息,即根目录和当前目录,path结构定义如下:
---------------------------------------------------------------------
include/linux/path.h
struct path {
struct vfsmount *mnt;
struct dentry *dentry;
};
---------------------------------------------------------------------
mnt:描述目录所安装的文件系统对象
dentry:描述目录的目录项
还有一个表表示进程打开的文件,即task_struct结构的files_struct类型的files字段。它给出了所有的进程描述符的使用情况,其file结构指针数组成员给出了文件描述符的信息,其定义如下:
---------------------------------------------------------------------
include/linux/fdtable.h
struct files_struct {
/*
* read mostly part
*/
atomic_t count; /* 共享该表的进程数目 */
/* 文件描述符表 */
struct fdtable *fdt;
struct fdtable fdtab;
/*
* written part on a separate cache line in SMP
*/
/* 用于表中字段的读/写自旋锁 */
spinlock_t file_lock ____cacheline_aligned_in_smp;
int next_fd; /* 所分配的最大文件描述符加1 */
/* 执行exec() 时需要关闭的文件描述符的集合 */
struct embedded_fd_set close_on_exec_init;
/* 文件描述符的初始集合 */
struct embedded_fd_set open_fds_init;
/* 文件对象指针的初始化数组 */
struct file * fd_array[NR_OPEN_DEFAULT];
};
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-76274-1.html
”我摇摇头说
嘻嘻