在task_struct
中,我们可以发现有:
struct mm_struct *mm, *active_mm;
struct files_struct *files;
files_struct
包含指向多达 256 个文件数据结构的指针,每个结构都描述了该进程正在使用的一个文件。
struct file * fd_array[NR_OPEN_DEFAULT];
mm_struct
包含一个 vm_area_struct
。
struct vm_area_struct * mmap; /* list of VMAs */
而在vm_area_struct
中,我们可以发现:
struct file * vm_file; /* File we map to (can be NULL). */
所以我的问题是:
fd_array
和vm_file
中的文件有什么关系?fd_array
中显示的所有文件是否也将以类似于图片所示的方式映射到vm_area_struct
中?或者,vm_area_struct
中映射的所有文件是否都会显示在fd_array
中?
谢谢,
(来源:duartes.org)
最佳答案
fd_array
中的文件是那些当前具有与之关联的文件描述符的文件(例如,使用 open()
、socket()
或类似的),而由 VMA 链接的是映射到进程内存中的那些(例如,使用 mmap()
)。文件可以属于任一类别,也可以属于两者,因此 fd_array
中的文件不一定由 VMA 链接,反之亦然。
关于c - 一个进程的文件,mm_struct和files_struct中文件的关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7746238/