1 /* 2 * Copyright (c) 1982, 1986, 1989 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)proc.h 7.7 (Berkeley) 08/26/89 7 */ 8 9 /* 10 * One structure allocated per session. 11 */ 12 struct session { 13 struct proc *s_leader; /* pointer to session leader */ 14 int s_count; /* number of pgrps in session */ 15 }; 16 17 /* 18 * One structure allocated per process group. 19 */ 20 struct pgrp { 21 struct pgrp *pg_hforw; /* forward link in hash bucket */ 22 struct proc *pg_mem; /* pointer to pgrp members */ 23 struct session *pg_session; /* pointer to session */ 24 pid_t pg_id; /* pgrp id */ 25 short pg_jobc; /* # procs qualifying pgrp for job control */ 26 }; 27 28 /* 29 * One structure allocated per active 30 * process. It contains all data needed 31 * about the process while the 32 * process may be swapped out. 33 * Other per process data (user.h) 34 * is swapped with the process. 35 */ 36 struct proc { 37 struct proc *p_link; /* linked list of running processes */ 38 struct proc *p_rlink; 39 struct proc *p_nxt; /* linked list of allocated proc slots */ 40 struct proc **p_prev; /* also zombies, and free proc's */ 41 struct pte *p_addr; /* u-area kernel map address */ 42 char p_usrpri; /* user-priority based on p_cpu and p_nice */ 43 char p_pri; /* priority, negative is high */ 44 char p_cpu; /* cpu usage for scheduling */ 45 char p_stat; 46 char p_time; /* resident time for scheduling */ 47 char p_nice; /* nice for cpu usage */ 48 char p_slptime; /* time since last block */ 49 char p_cursig; 50 int p_sig; /* signals pending to this process */ 51 int p_sigmask; /* current signal mask */ 52 int p_sigignore; /* signals being ignored */ 53 int p_sigcatch; /* signals being caught by user */ 54 int p_flag; 55 uid_t p_uid; /* effective user id */ 56 uid_t p_ruid; /* real user id */ 57 uid_t p_svuid; /* saved effective user id */ 58 gid_t p_rgid; /* real group id */ 59 gid_t p_svgid; /* saved effective group id */ 60 pid_t p_pid; /* unique process id */ 61 pid_t p_ppid; /* process id of parent */ 62 u_short p_xstat; /* Exit status for wait */ 63 struct rusage *p_ru; /* exit information */ 64 short p_poip; /* page outs in progress */ 65 short p_szpt; /* copy of page table size */ 66 size_t p_tsize; /* size of text (clicks) */ 67 size_t p_dsize; /* size of data space (clicks) */ 68 size_t p_ssize; /* copy of stack size (clicks) */ 69 size_t p_rssize; /* current resident set size in clicks */ 70 size_t p_maxrss; /* copy of u.u_limit[MAXRSS] */ 71 size_t p_swrss; /* resident set size before last swap */ 72 swblk_t p_swaddr; /* disk address of u area when swapped */ 73 caddr_t p_wchan; /* event process is awaiting */ 74 struct text *p_textp; /* pointer to text structure */ 75 struct pte *p_p0br; /* page table base P0BR */ 76 struct proc *p_xlink; /* linked list of procs sharing same text */ 77 int p_cpticks; /* ticks of cpu time */ 78 fixpt_t p_pctcpu; /* %cpu for this process during p_time */ 79 short p_ndx; /* proc index for memall (because of vfork) */ 80 short p_idhash; /* hashed based on p_pid for kill+exit+... */ 81 struct proc *p_pptr; /* pointer to process structure of parent */ 82 struct proc *p_cptr; /* pointer to youngest living child */ 83 struct proc *p_osptr; /* pointer to older sibling processes */ 84 struct proc *p_ysptr; /* pointer to younger siblings */ 85 struct pgrp *p_pgrp; /* pointer to process group */ 86 #define p_session p_pgrp->pg_session 87 #define p_pgid p_pgrp->pg_id 88 struct proc *p_pgrpnxt; /* pointer to next process in process group */ 89 struct itimerval p_realtimer; 90 struct quota *p_quota; /* quotas for this process */ 91 int p_traceflag; /* kernel tracing flags (facilities) */ 92 struct vnode *p_tracep;/* trace to vnode */ 93 #if defined(tahoe) 94 int p_ckey; /* code cache key */ 95 int p_dkey; /* data cache key */ 96 #endif 97 }; 98 99 #define PIDHSZ 64 100 #define PIDHASH(pid) ((pid) & (PIDHSZ - 1)) 101 102 #ifdef KERNEL 103 pid_t pidhash[PIDHSZ]; 104 struct proc *pfind(); 105 struct pgrp *pgrphash[PIDHSZ]; 106 struct pgrp *pgfind(); /* find process group by id */ 107 struct proc *proc, *procNPROC; /* the proc table itself */ 108 struct proc *freeproc, *zombproc, *allproc; 109 /* lists of procs in various states */ 110 int nproc; 111 112 #define NQS 32 /* 32 run queues */ 113 struct prochd { 114 struct proc *ph_link; /* linked list of running processes */ 115 struct proc *ph_rlink; 116 } qs[NQS]; 117 int whichqs; /* bit mask summarizing non-empty qs's */ 118 119 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p)) 120 #define PGRP_JOBC(p) (((p)->p_pgrp != (p)->p_pptr->p_pgrp) && \ 121 ((p)->p_session == (p)->p_pptr->p_session)) 122 #endif 123 124 /* stat codes */ 125 #define SSLEEP 1 /* awaiting an event */ 126 #define SWAIT 2 /* (abandoned state) */ 127 #define SRUN 3 /* running */ 128 #define SIDL 4 /* intermediate state in process creation */ 129 #define SZOMB 5 /* intermediate state in process termination */ 130 #define SSTOP 6 /* process being traced */ 131 132 /* flag codes */ 133 #define SLOAD 0x0000001 /* in core */ 134 #define SSYS 0x0000002 /* swapper or pager process */ 135 #define SLOCK 0x0000004 /* process being swapped out */ 136 #define SSWAP 0x0000008 /* save area flag */ 137 #define STRC 0x0000010 /* process is being traced */ 138 #define SWTED 0x0000020 /* another tracing flag */ 139 #define SULOCK 0x0000040 /* user settable lock in core */ 140 #define SPAGE 0x0000080 /* process in page wait state */ 141 #define SKEEP 0x0000100 /* another flag to prevent swap out */ 142 #define SOMASK 0x0000200 /* restore old mask after taking signal */ 143 #define SWEXIT 0x0000400 /* working on exiting */ 144 #define SPHYSIO 0x0000800 /* doing physical i/o */ 145 #define SVFORK 0x0001000 /* process resulted from vfork() */ 146 #define SVFDONE 0x0002000 /* another vfork flag */ 147 #define SNOVM 0x0004000 /* no vm, parent in a vfork() */ 148 #define SPAGV 0x0008000 /* init data space on demand, from vnode */ 149 #define SSEQL 0x0010000 /* user warned of sequential vm behavior */ 150 #define SUANOM 0x0020000 /* user warned of random vm behavior */ 151 #define STIMO 0x0040000 /* timing out during sleep */ 152 #define SNOCLDSTOP 0x0080000 /* no SIGCHLD when children stop */ 153 /* was SOUSIG 0x0100000 /* using old signal mechanism */ 154 #define SOWEUPC 0x0200000 /* owe process an addupc() call at next ast */ 155 #define SSEL 0x0400000 /* selecting; wakeup/waiting danger */ 156 #define SLOGIN 0x0800000 /* a login process (legit child of init) */ 157 #define SPTECHG 0x1000000 /* pte's for process have changed */ 158 #define SKTR 0x2000000 /* pass kernel tracing flags to children */ 159 #define SEXEC 0x8000000 /* process called exec */ 160