- 帖子
- 330
- 主题
- 18
- 精华
- 4
- 可用积分
- 536
- 专家积分
- 43
- 在线时间
- 71 小时
- 注册时间
- 2006-04-05
- 最后登录
- 2010-10-29
状态:...当前离线... [微博] [博客] [短信] | 4. 进程相关的信息
和进程相关的信息, 涉及到四个重要的数据结构: file, fs_struct, files_struct 和 namespace
相关的数据结构为:
struct file { struct list_head f_list; struct dentry *f_dentry; struct vfsmount *f_vfsmnt; struct file_operations *f_op; atomic_t f_count; unsigned int f_flags; mode_t f_mode; int f_error; loff_t f_pos; struct fown_struct f_owner; unsigned int f_uid, f_gid; struct file_ra_state f_ra;
size_t f_maxcount; unsigned long f_version; void *f_security;
/* needed for tty driver, and maybe others */ void *private_data;
#ifdef CONFIG_EPOLL /* Used by fs/eventpoll.c to link all the hooks to this file */ struct list_head f_ep_links; spinlock_t f_ep_lock; #endif /* #ifdef CONFIG_EPOLL */ struct address_space *f_mapping; };
-------------------------------------------------------------------------------
struct fs_struct { atomic_t count; rwlock_t lock; int umask; struct dentry * root, * pwd, * altroot; struct vfsmount * rootmnt, * pwdmnt, * altrootmnt; };
-------------------------------------------------------------------------------
struct files_struct { atomic_t count; spinlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */ int max_fds; int max_fdset; int next_fd; struct file ** fd; /* current fd array */ fd_set *close_on_exec; fd_set *open_fds; fd_set close_on_exec_init; fd_set open_fds_init; struct file * fd_array[NR_OPEN_DEFAULT]; };
-------------------------------------------------------------------------------
struct namespace { atomic_t count; struct vfsmount * root; struct list_head list; struct rw_semaphore sem; };
每个进程都有自己的namespace.
fs_struct用于表示进程与文件系统之间的结构关系,比如当前的工作目录,进程的根目录等等.
files_struct 用于表示当前进程打开的文件.
而对于每一个打开的文件,由file对象来表示.
Linux中,常常用文件描述符(file descriptor)来表示一个打开的文件,这个描述符的值往往是一个大于或等于0的整数. 而这个整数,其实就是在files_struct中file数组fd的下标. 对于所有打开的文件, 这些文件描述符会存储在open_fds的位图中. | |