PCB进程控制块

2019-07-14 11:14发布

include/linux/sched.h struct task_struct { volatile long state; struct thread_info *thread_info; atomic_t usage; unsigned long flags; unsigned long ptrace; int lock_depth; int prio, static_prio; struct list_head run_list; prio_array_t *array; unsigned long sleep_avg; long interactive_credit; unsigned long long timestamp; int activated; unsigned long policy; cpumask_t cpus_allowed; unsigned int time_slice, first_time_slice; struct list_head tasks; struct list_head ptrace_children; struct list_head ptrace_list; struct mm_struct *mm, *active_mm; ... struct linux_binfmt *binfmt; int exit_code, exit_signal; int pdeath_signal; ... pid_t pid; pid_t tgid; ... struct task_struct *real_parent; struct task_struct *parent; struct list_head children; struct list_head sibling; struct task_struct *group_leader; ... struct pid_link pids[PIDTYPE_MAX]; wait_queue_head_t wait_chldexit; struct completion *vfork_done; int __user *set_child_tid; int __user *clear_child_tid; unsigned long rt_priority; unsigned long it_real_value, it_prof_value, it_virt_value; unsigned long it_real_incr, it_prof_incr, it_virt_incr; struct timer_list real_timer; unsigned long utime, stime, cutime, cstime; unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; u64 start_time; ... uid_t uid,euid,suid,fsuid; gid_t gid,egid,sgid,fsgid; struct group_info *group_info; kernel_cap_t cap_effective, cap_inheritable, cap_permitted; int keep_capabilities:1; struct user_struct *user; ... struct rlimit rlim[RLIM_NLIMITS]; unsigned short used_math; char comm[16]; ... int link_count, total_link_count; ... struct fs_struct *fs; ... struct files_struct *files; ... unsigned long ptrace_message; siginfo_t *last_siginfo; ... };

调度数据成员:
1) vo latile long state
表示进程的当前状态。进程运行时, 它会根据具体情况改变状态。进程状态总共有TASK RUNN ING ( 可运行状态)、TASK INTERRUPT IBLE ( 可中断的等待状态)、TASK UNINTERRUPT IBLE(不可中断的等待状态)、TASK ZOMB IE( 僵死状态)、TASK STOPPED(暂停状态) 等5种。
2) long pr io rity进程优先级, prio rity 的值给出了进程每次获取CPU 后, 可使用的时间片长度( 单位是jiffies)。
3) unsigned long rt_priority rt_priority 的值给出了实时进程的优先级, rt_priority 
1000给出进程每次获取CPU 后, 可使用的时间片长度(单位是jiffies)。
4) long counter在轮转法调度时counter表示当前进程还可运行多久。在进程开始时被赋为priority的值, 以后每隔一个时钟中断递减1,减到0时引起新一轮调度。
5) unsigned long policy表示该进程的进程调度策略。调度策略有:
SCH ED_OTHER 0, 非实时进程, 用基于优先权的轮转法。
SCH ED_FIFO 1, 实时进程, 用先进先出算法。
SCH ED_RR 2, 实时进程, 用基于优先权的轮转法
 
进程队列指针:
1) struc t task_struct* next_task, * prev_task
在Linux 中所有进程(以PCB 的形式)组成一个双向链表,
next_task和prev_task是链表的前后向指针。
2) struct task_struct* p_opptr, * p_pptr
struct task_struc t* p_cptr, * p_ysptr, * p_osptr
以上分别是指向该进程的原始父进程、父进程、子进程和新
老兄弟进程的指针。
3) struct task_struct* pidhash_next
struct task_struct** pidhash_pprev
用于链入进程hash表的前后指针。系统进程除了链入双
向链表外, 还被加到hash表中。
 
进程标识:
uid_t uid  gid_t gid uid和gid分别是运行进程的用
户标识和用户组标识。
pid_t pid  pid_t pgrp pid和pgrp分别是运行进程的
进程标识号和进程组标识号
时间数据成员:
long per_cpu_utime [ NR_CPUS ] per_cpu_stime
[ NR_CPUS]
per_cpu_utime 是用户态进程运行的时间, per_cpu_
stime是内核态进程运行的时间
进程创建时间unsigned long start_time


文件系统数据成员:
struct fs_struct* fs
fs保存了进程本身与VFS( 虚拟文件系统)的关系信息。
struct fs_struct
{
 atom ic_t count;
 rw lock_t lock;
 int umask;
 struct dentry* root, * pwd, * altroot;
 struct vfsm ount* rootmnt, * pwdmnt, * altrootmnt;
}
其中root、rootm nt是根目录的dentry 和其mount点的vfsmount。
pwd、pwdmnt 是当前工作目录的dentry 和其mount 点的vfs..
mount。altroot、altrootmnt是保存根节点被替换之后原来根目标
的dentry和其mount点的vfsmount。
 
内存数据成员:
1) struct mm_struct* mm
在Linux 中, 采用按需分页的策略解决进程的内存需求。
task_struct的数据成员mm 指向关于存储管理的mm_truc t结
构。
2) struct mm_struct* active_mm
active_mm 指向活动地址空间。
3) mm_segm ent_t addr_ lim it
表示线程空间地址。
用户线程空间地址: 0..0xBFFFFFFF。
内核线程空间地址: 0..0xFFFFFFFF
4) spinlock_t alloc_ lock
用于申请空间时用的自旋锁。自旋锁的主要功能是临界区
保护。
 
页面管理:
1) int swappable: 1
进程占用的页面是否可换出。swappab le为1表示可换出。
2) unsigned long min_flt, maj_ flt
该进程累计minor缺页次数和major缺页次数。
3) unsigned long nswap
该进程累计换出页面数。
4) unsigned long swap_cnt
下一次循环最多可换出的页数。