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 */
int p_wchan;/* event process is awaiting */
int*p_textp;/* pointer to text structure */
} proc[NPROC];
/* stat codes */
#define SSLEEP 1 /* sleeping on high priority */
#define SWAIT 2 /* sleeping on low priority */
#define SRUN 3 /* running */
#define SIDL 4 /* intermediate state in process creation */
#define SZOMB 5 /* intermediate state in process termination */
#define SSTOP 6 /* process being traced */
/* flag codes */
#define SLOAD 01 /* in core */
#define SSYS 02 /* scheduling process */
#define SLOCK 04 /* process cannot be swapped */
#define SSWAP 010 /* process is being swapped out */
#define STRC 020 /* process is being traced */
#define SWTED 040 /* another tracing flag */
注意在定义结构的同时还定义了结构数组变量proc[NPROC],它存放了所有进程的proc上下文。proc结构又称为进程控制块PCB(Process Control Block),它记录了进程相关的很多信息,包括优先级、驻留时间、进程ID、交换区地址和程序段信息等,它主要用于进程调度和同步。NPROC在param.h中定义,为64,这样系统最多支持64个进程。
/*
* Text结构,每个程序段分配一个(但fork创建的
* 父子进程会共享)。它的操作函数在text.c中。
*/ /*
* Text structure.
* One allocated per pure
* procedure on swap device.
* Manipulated by text.c
*/ struct text { int x_daddr;/* disk address of segment */ int x_caddr;/* core address, if loaded */ int x_size;/* size (*64) */ int*x_iptr;/* inode of prototype */ char x_count;/* reference count */ char x_ccount;/* number of loaded references */ } text[NTEXT];
#define NBUF 15 /* size of buffer cache */ #define NINODE 100 /* number of in core inodes */ #define NFILE 100 /* number of in core file structures */ #define NMOUNT 5 /* number of mountable file systems */ #define NEXEC 3 /* number of simultaneous exec's */ #define MAXMEM (64*32)/* max core per process - first # is Kw */ #define SSIZE 20 /* initial stack size (*64 bytes) */ #define SINCR 20 /* increment of stack (*64 bytes) */ #define NOFILE 15 /* max open files per process */ #define CANBSIZ 256 /* max size of typewriter line */ #define CMAPSIZ 100 /* size of core allocation area */ #define SMAPSIZ 100 /* size of swap allocation area */ #define NCALL 20 /* max simultaneous time callouts */ #define NPROC 50 /* max number of processes */ #define NTEXT 40 /* max number of pure texts */ #define NCLIST 100 /* max total clist size */ #define HZ 60 /* Ticks/second of the clock */
/*
* priorities
* probably should not be
* altered too much
*/
#define USIZE 16 /* size of user block (*64) */ #defineNULL 0 #define NODEV (-1) #define ROOTINO 1 /* i number of all roots */ #define DIRSIZ 14 /* max characters per directory */
/*
* structure to access an
* integer in bytes
*/ struct { char lobyte; char hibyte; };
/*
* structure to access an integer
*/ struct { int integ; };
/*
* The user structure.
* One allocated per process.
* Contains all per process data
* that doesn’t need to be referenced
* while the process is swapped.
* The user block is USIZE*64 bytes
* long; resides at virtual kernel
* loc 140000; contains the system
* stack per user; is cross referenced
* with the proc structure for the
* same process.
*/ struct user { int u_rsav[2];/* save r5,r6 when exchanging stacks */ int u_fsav[25];/* save fp registers */ /* rsav and fsav must be first in structure */ char u_segflg;/* flag for IO; user or kernel space */ char u_error;/* return error code */ char u_uid;/* effective user id */ char u_gid;/* effective group id */ char u_ruid;/* real user id */ char u_rgid;/* real group id */ int u_procp;/* pointer to proc structure */ char*u_base;/* base address for IO */ char*u_count;/* bytes remaining for IO */ char*u_offset[2];/* offset in file for IO */ int*u_cdir;/* pointer to inode for current directory */ char u_dbuf[DIRSIZ];/* current pathname component */ char*u_dirp;/* current pointer to inode */ struct{/* current directory entry */ int u_ino; char u_name[DIRSIZ]; } u_dent; int*u_pdir;/* inode of parent directory of dirp */ int u_uisa[16];/* prototype segmentation addresses */ int u_uisd[16];/* prototype segmentation descriptors */ int u_ofile[NOFILE];/* pointers to file structures of open files */ int u_arg[5];/* arguments to current system call */ int u_tsize;/* text size (*64) */ int u_dsize;/* data size (*64) */ int u_ssize;/* stack size (*64) */ int u_sep;/* flag for I and D separation */ int u_qsav[2];/* label variable for quits & interrupts */ int u_ssav[2];/* label variable for swapping */ int u_signal[NSIG];/* disposition of signals */ int u_utime;/* this process user time */ int u_stime;/* this process system time */ int u_cutime[2];/* sum of childs’ utimes */ int u_cstime[2];/* sum of childs’ stimes */ int*u_ar0;/* address of users saved R0 */ int u_prof[4];/* profile arguments */ char u_intflg;/* catch intr from sys */ /* kernel stack per user
* extends from u + USIZE*64
* backward not to reach here
*/ } u;
/* u_error codes */ /* See section "INTRO(II)" of
* the UNIX Programmer’s manual
* for the meanings of these codes. */ #define EFAULT 106 //地址空间访问出错,比如访问了未映射的虚拟地址。