🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
#**PCB概述** 引用自《莱昂氏UNIX源代码分析》P30页358行,源代码如下: ``` struct proc { char p_stat; char p_flag; char p_pri; // priority,negative is high char p_sig; // signal number sent to this process char p_uid; // user id, used to direct tty signals char p_time; // resident time for scheduling char p_cpu; // cpu usage for scheduling char p_nice; // nice for scheduling int p_ttyp; // controlling tty int p_pid; // unique process id int p_ppid; // process id of parent int p_addr; // address of swappable image int p_size; // size of swappable image(\*64 bytes) int p_wehan; // event process is awaiting int * p_textp; // pointer to text structure } proc[NPROC]; ``` 这就是在早期UNIX操作系统中的PCB进程控制块儿的15个字段源代码。 要想读懂这15字段光靠注释和书中的解释是远远不够的。 可以把把这15个字段分成3层(它的属性:alive、3D动态): **cpu层;(内核cpu)** **程序员层;(用户user)** **程序层;(进程)** 基本上操作系统也是靠这个结构体来完成对应的操作算法的。 **1、程序加载到内存转变为进程**,**2、进程的3层调用**:cpu调用(改用调度?),进程相互调用(改用通信?),用户调用(改用操作?),**3、各个字段处理对应需求的数据结构**。 我使用3D动态这个词的原因,大家不妨想一想: 如果,我把一个进程从计算机里拉出来(类似拉心脏),是不是有好多连接RAM、CPU、鼠标、显示器等有关的tty字段,这和血管不是很像么?