PCB(process control block),进程控制块,是我们学习操作系统后遇到的第一个数据结构描述,它是对系统的进程进行管理的重要依据,和进程管理相关的操作无一不用到PCB中的内容。一般情况下,PCB中包含以下内容:
(1)进程标识符(内部,外部)
(2)处理机的信息(通用寄存器,指令计数器,PSW,用户的栈指针)。
(3)进程调度信息(进程状态,进程的优先级,进程调度所需的其它信息,事件)
(4)进程控制信息(程序的数据的地址,资源清单,进程同步和通信机制,链接指针)
数据结构中定义的内容是为后面的管理提供支持的,所以不同的操作系统根据自己的特点又对PCB的内容做了一些调整。下面整理了比较流行的一些操作系统的PCB结构,供参考。
1.Linux的进程块
在创建一个新进程时,系统在内存中申请一个空的task_struct区,即空闲PCB块,并填入所需信息。同时将指向该结构的指针填入到task[]数组中。当前处于运行状态进程的PCB用指针数组current_set[]来指出。这是因为Linux支持多处理机系统,系统内可能存在多个同时运行的进程,故current_set定义成指针数组。
Linux系统的PCB包括很多参数,每个PCB约占1KB多的内存空间。用于表示PCB的结构task_struct简要描述如下:
struct task_struct{
…
unsigned short uid;
int pid;
int processor;
…
volatile long state;
long prority;
unsighed long rt_prority;
long counter;
unsigned long flags;
unsigned long policy;
…
Struct task_struct *next_task, *prev_task;
Struct task_struct *next_run,*prev_run;
Struct task_struct *p_opptr,*p_pptr,*p_cptr,*pysptr,*p_ptr;
…
};
下面对部分数据成员进行说明:
(1)unsigned short pid 为用户标识
(2)int pid 为进程标识
(3)int processor标识用户正在使用的CPU,以支持对称多处理机方式;
(4)volatile long state 标识进程的状态,可为下列六种状态之一:
可运行状态(TASK-RUNING);
可中断阻塞状态(TASK-UBERRUPTIBLE)
不可中断阻塞状态(TASK-UNINTERRUPTIBLE)
僵死状态(TASK-ZOMBLE)
暂停态(TASK_STOPPED)
交换态(TASK_SWAPPING)
(5)long prority表示进程的优先级
(6)unsigned long rt_prority 表示实时进程的优先级,对于普通进程无效
(7)long counter 为进程动态优先级计数器,用于进程轮转调度算法
(8)unsigned long policy 表示进程调度策略,其值为下列三种情况之一:
SCHED_OTHER(值为0)对应普通进程优先级轮转法(round robin)
SCHED_FIFO(值为1)对应实时进程先来先服务算法;
SCHED_RR(值为2)对应实时进程优先级轮转法
(9)struct task_struct *next_task,*prev_task为进程PCB双向链表的前后项指针
(10)struct task_struct *next_run,*prev_run为就绪队列双向链表的前后项指针
(11)struct task_struct *p_opptr,*p_pptr,*p_cptr,*p_ysptr,*p_ptr指明进程家族间的关系,分别为指向祖父进程、父进程、子进程以及新老进程的指针。
2.Unix的进程块(教科书10.2节有详细介绍)
在 UNIX 系统Ⅴ中, 把进程控制块分为四部分:
讯享网
讯享网 <div> <div> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/19af9e1b452cfe3a22c0eb21f657e248.gif" width="19" height="19" />进程表项 </div> <div> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/6f4285d2aa3c1c6cb523bb6b36bfc56b.gif" width="16" height="16" /> 进程标识符(PID) </p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/75c2dc9d49c1682b35693fd6d9feed27.gif" width="16" height="16" /> 用户标识符(UID)</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/d53ded9d92c8317.gif" width="16" height="16" /> 进程状态</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/6b14b9815a4af458f698aadc9c06da08.gif" width="16" height="16" /> 事件描述符</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/6f9a2ded8cefbcfdfa79.gif" width="16" height="16" /> 进程和U区在内存或外存的地址</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/5a9c2cb6e7173c47e06a264f8a.gif" width="16" height="16" /> 软中断信息</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/93a4ab6e1b6970f95aba9bec36040abe.gif" width="16" height="16" /> 计时域</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/50d79fa6d6573ab8e78cf864e3bbc2eb.gif" width="16" height="16" /> 进程的大小</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/bd5fcd5b25c0a176c67fad7dfccc14d8.gif" width="16" height="16" /> 偏置值nice</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/8cd4c0f67b557cf5430cf37d037af427.gif" width="16" height="16" /> P-Link指针</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/cf62b220bbbfdb8e1e.gif" width="16" height="16" /> 指向U区进程正文、数据及栈在内存区域的指针</p> </div> </div> </td></tr><tr><td align="right"><map name="FrontPageMap7MapMapMap2"><area href="https://blog.csdn.net#页头" rel="nofollow" /></map></td></tr><tr><td> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/36ed7200b84e180f888fa9dfbe.gif" width="19" height="19" /> U 区 </p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/8b310d0fa7f4dfd29889a94.gif" width="16" height="16" /> 进程表项指针 </p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/7e80a481a1f3a0cbea137df8805f842d.gif" width="16" height="16" /> 真正用户标识符u-ruid(real user ID)</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/6769a38aae29d8997c073ee049d60e61.gif" width="16" height="16" /> 有效用户标识符u-euid(effective user ID)</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/ef3af2c9edf6.gif" width="16" height="16" /> 用户文件描述符表</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/59ee54bce8091f62dd73b2de822e35e3.gif" width="16" height="16" /> 当前目录和当前根</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/f05452a015d55b0c74873fa0f7d02f63.gif" width="16" height="16" /> 计时器</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/c6352d9967dcbe99a1171eef6.gif" width="16" height="16" /> 内部I/O参数</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/c4efa4b1c81f52fa01abbd180bc09e5a.gif" width="16" height="16" /> 限制字段</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/261e310c73276ef22feacdf941.gif" width="16" height="16" /> 差错字段</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/fc8bc1e9f5ff73da51dbfcd57.gif" width="16" height="16" /> 返回值</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/b2f98c9d42b61f90bf648b4f5174d863.gif" width="16" height="16" /> 信号处理数组</p> </td></tr><tr><td align="right"><map name="FrontPageMap7MapMapMap3"><area href="https://blog.csdn.net#页头" rel="nofollow" /></map></td></tr><tr><td><img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/105d0468c3665cd20cdd9689c83b0e00.gif" width="19" height="19" /> 进程区表 <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/f4f2205ebcd0e0e77270f4481aa40b15.gif" width="16" height="16" /> 区的类型和大小 </p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/5eafe061992bcf065db97de6f7.gif" width="16" height="16" /> 区的状态</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/b4abce4a8f4feb7fab034a33d5dffd31.gif" width="16" height="16" /> 区在物理存储器中的位置</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/e290dff829afcda035f489dea.gif" width="16" height="16" /> 引用计数</p> <p> <img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/e41ed3d5e10a540c49****141.gif" width="16" height="16" /> 指向文件索引结点的指针</p> </td></tr><tr><td align="right"><map name="FrontPageMap7MapMapMap4"><area href="https://blog.csdn.net#页头" rel="nofollow" /></map></td></tr><tr><td><img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/332c0b87aed235f730eef6bc73cc5410.gif" width="19" height="19" />系统区表</td></tr><tr><td><img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/8f32a73d3871c5a86717ebe011924e86.gif" width="16" height="16" /> 进程区表项、系统区表项和区的关系</td></tr><tr><td align="middle"> <div border="0" width="100" bgcolor="#3399ff"><tbody><tr><td></td></tr></tbody></div> </td></tr><tr><td align="right"><map name="FrontPageMap7MapMapMap7"><area href="https://blog.csdn.net#页头" rel="nofollow" /></map></td></tr><tr><td><img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/b84caa37cf5319b01d4bba307dabaa9b.gif" width="16" height="16" /> 进程的数据结构</td></tr><tr><td align="middle"> <div border="0" width="100" bgcolor="#ffcccc"><tbody><tr><td><img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/5fbdcd203baf6765bfd414ed84aba509.png" width="346" height="208" /></td></tr></tbody></div> </td></tr><tr><td align="right"><map name="FrontPageMap7MapMap"><area href="https://blog.csdn.net#页头" rel="nofollow" /></map></td></tr></tbody></div>
讯享网 进程状态与进程映像

讯享网 <div border="0" width="100" bgcolor="#66ffcc"><tbody><tr><td><img alt="" src="https://i-blog.csdnimg.cn/blog_migrate/16d299ec1240d9999da5fb2de7b6a5e7.png" width="346" height="208" /></td></tr></tbody></div> </td></tr></tbody></div>
3.windows下的PCB
Windows中的进程控制块是EPROCESS结构, 线程控制块是ETHREAD结构. EPROCESS/ETHREAD的定义在inside windows2000中有比较详细的描述。
Windows的进程链表是一个双向环链表。这个环链表LIST_ENTRY结构把每个EPROCESS链接起来. 那么只要找到一个EPROCESS结构, 我们就可以遍历整个链表, 这就是枚举进程的原理。
建议:同学看看<<Windows核心编程>>这本书,对大家进行高级程序设计有很大的帮助
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/170305.html