Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A process's files, the relation between files in mm_struct and files_struct?

Tags:

c

linux

kernel

In task_struct, we can find there are:

struct mm_struct *mm, *active_mm;
struct files_struct *files;  

files_struct contains pointers to up to 256 file data structures, each one describing a file being used by this process.

struct file * fd_array[NR_OPEN_DEFAULT];

mm_struct contains a vm_area_struct.

struct vm_area_struct * mmap;           /* list of VMAs */

And in vm_area_struct, we can find:

struct file * vm_file;          /* File we map to (can be NULL). */

So my question are:

  1. what is the relationship between the files in fd_array and the vm_file?

  2. Are all the files shown up in the fd_array will also be mapped in the vm_area_struct in a way similar as shown in the picture? Or, are all the files mapped in the vm_area_struct will show up in the fd_array?

Thanks,

a busy cat
(source: duartes.org)

like image 642
sliter Avatar asked Oct 12 '11 20:10

sliter


1 Answers

The files in fd_array are those that currently have a file descriptor associated with them (eg. opened with open(), socket() or similar), and those linked by VMAs are those that are mapped into process memory (eg. with mmap()). Files can be in either category or in both, so those files in fd_array are not necessarily linked by a VMA and vice-versa.

like image 95
caf Avatar answered Oct 22 '22 09:10

caf