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.23 (Berkeley) 01/10/91 7 */ 8 9 /* 10 * One structure allocated per session. 11 */ 12 struct session { 13 int s_count; /* ref cnt; pgrps in session */ 14 struct proc *s_leader; /* session leader */ 15 struct vnode *s_ttyvp; /* vnode of controlling terminal */ 16 struct tty *s_ttyp; /* controlling terminal */ 17 }; 18 19 /* 20 * One structure allocated per process group. 21 */ 22 struct pgrp { 23 struct pgrp *pg_hforw; /* forward link in hash bucket */ 24 struct proc *pg_mem; /* pointer to pgrp members */ 25 struct session *pg_session; /* pointer to session */ 26 pid_t pg_id; /* pgrp id */ 27 int pg_jobc; /* # procs qualifying pgrp for job control */ 28 }; 29 30 /* 31 * One structure allocated per active 32 * process. It contains all data needed 33 * about the process while the 34 * process may be swapped out. 35 * Other per process data (user.h) 36 * is swapped with the process. 37 */ 38 39 struct proc { 40 struct proc *p_link; /* linked list of running processes */ 41 struct proc *p_rlink; 42 struct proc *p_nxt; /* linked list of allocated proc slots */ 43 struct proc **p_prev; /* also zombies, and free proc's */ 44 caddr_t p_addr; /* kernel virtual address of u-area */ 45 char p_usrpri; /* user-priority based on p_cpu and p_nice */ 46 char p_pri; /* priority, negative is high */ 47 char p_cpu; /* cpu usage for scheduling */ 48 char p_stat; 49 char p_time; /* resident time for scheduling */ 50 char p_nice; /* nice for cpu usage */ 51 char p_slptime; /* time since last block */ 52 char p_dupfd; /* sideways return value from fdopen XXX */ 53 int p_sig; /* signals pending to this process */ 54 int p_sigmask; /* current signal mask */ 55 int p_sigignore; /* signals being ignored */ 56 int p_sigcatch; /* signals being caught by user */ 57 int p_flag; 58 uid_t p_uid; /* effective user id */ 59 uid_t p_ruid; /* real user id */ 60 uid_t p_svuid; /* saved effective user id */ 61 gid_t p_rgid; /* real group id */ 62 gid_t p_svgid; /* saved effective group id */ 63 pid_t p_pid; /* unique process id */ 64 pid_t p_ppid; /* process id of parent */ 65 u_short p_xstat; /* Exit status for wait; also stop signal */ 66 struct rusage *p_ru; /* exit information */ 67 struct vm_map *p_map; /* VM address map */ 68 caddr_t p_shm; /* SYS5 shared memory private data */ 69 int p_thread; /* id for this "thread" (Mach glue) XXX */ 70 struct filedesc *p_fd; /* ptr to open files structure */ 71 int p_pad1; 72 segsz_t p_rssize; /* current resident set size in clicks */ 73 segsz_t p_maxrss; /* copy of u.u_limit[MAXRSS] */ 74 segsz_t p_swrss; /* resident set size before last swap */ 75 swblk_t p_swaddr; /* disk address of u area when swapped */ 76 caddr_t p_wchan; /* event process is awaiting */ 77 int pad2[3]; 78 int p_cpticks; /* ticks of cpu time */ 79 fixpt_t p_pctcpu; /* %cpu for this process during p_time */ 80 short p_ndx; /* proc index for memall (because of vfork) */ 81 struct proc *p_hash; /* hashed based on p_pid for kill+exit+... */ 82 struct proc *p_pptr; /* pointer to process structure of parent */ 83 struct proc *p_cptr; /* pointer to youngest living child */ 84 struct proc *p_osptr; /* pointer to older sibling processes */ 85 struct proc *p_ysptr; /* pointer to younger siblings */ 86 struct pgrp *p_pgrp; /* pointer to process group */ 87 #define p_session p_pgrp->pg_session 88 #define p_pgid p_pgrp->pg_id 89 struct proc *p_pgrpnxt; /* pointer to next process in process group */ 90 struct itimerval p_realtimer; 91 int p_traceflag; /* kernel trace points */ 92 struct vnode *p_tracep;/* trace to vnode */ 93 char p_comm[MAXCOMLEN+1]; 94 char p_logname[MAXLOGNAME]; 95 char *p_wmesg; 96 struct timeval p_utime; /* user time */ 97 struct timeval p_stime; /* system time */ 98 #if defined(tahoe) 99 int p_ckey; /* code cache key */ 100 int p_dkey; /* data cache key */ 101 #endif 102 }; 103 104 /* 105 * proc ops return arrays of augmented proc structures 106 */ 107 struct kinfo_proc { 108 struct proc kp_proc; /* proc structure */ 109 struct eproc { 110 struct proc *e_paddr; /* address of proc */ 111 struct session *e_sess; /* session pointer */ 112 pid_t e_pgid; /* process group id */ 113 short e_jobc; /* job control counter */ 114 dev_t e_tdev; /* controlling tty dev */ 115 pid_t e_tpgid; /* tty process group id */ 116 struct session *e_tsess; /* tty session pointer */ 117 #define WMESGLEN 7 118 char e_wmesg[WMESGLEN+1]; /* wchan message */ 119 segsz_t e_xsize; /* text size */ 120 short e_xrssize; /* text rss */ 121 short e_xccount; /* text references */ 122 short e_xswrss; 123 long e_flag; 124 #define EPROC_CTTY 0x01 /* controlling tty vnode active */ 125 #define EPROC_SLEADER 0x02 /* session leader */ 126 long e_spare[7]; 127 } kp_eproc; 128 }; 129 130 #ifdef KERNEL 131 /* 132 * We use process IDs <= PID_MAX; 133 * PID_MAX + 1 must also fit in a pid_t 134 * (used to represent "no process group"). 135 */ 136 #define PID_MAX 30000 137 #define NO_PID 30001 138 #define PIDHASH(pid) ((pid) & pidhashmask) 139 extern int pidhashmask; /* in param.c */ 140 extern struct proc *pidhash[]; /* in param.c */ 141 struct proc *pfind(); /* find process by id */ 142 extern struct pgrp *pgrphash[]; /* in param.c */ 143 struct pgrp *pgfind(); /* find process group by id */ 144 struct proc *proc, *procNPROC; /* the proc table itself */ 145 struct proc *freeproc, *zombproc, *allproc; 146 /* lists of procs in various states */ 147 int nproc; 148 149 #define NQS 32 /* 32 run queues */ 150 struct prochd { 151 struct proc *ph_link; /* linked list of running processes */ 152 struct proc *ph_rlink; 153 } qs[NQS]; 154 int whichqs; /* bit mask summarizing non-empty qs's */ 155 156 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p)) 157 #define SESSHOLD(s) ((s)->s_count++) 158 #define SESSRELE(s) { \ 159 if (--(s)->s_count == 0) \ 160 FREE(s, M_SESSION); \ 161 } 162 #endif 163 164 /* stat codes */ 165 #define SSLEEP 1 /* awaiting an event */ 166 #define SWAIT 2 /* (abandoned state) */ 167 #define SRUN 3 /* running */ 168 #define SIDL 4 /* intermediate state in process creation */ 169 #define SZOMB 5 /* intermediate state in process termination */ 170 #define SSTOP 6 /* process being traced */ 171 172 /* flag codes */ 173 #define SLOAD 0x0000001 /* in core */ 174 #define SSYS 0x0000002 /* swapper or pager process */ 175 #define SLOCK 0x0000004 /* process being swapped out */ 176 #define SSWAP 0x0000008 /* save area flag */ 177 #define STRC 0x0000010 /* process is being traced */ 178 #define SWTED 0x0000020 /* another tracing flag */ 179 #define SSINTR 0x0000040 /* sleep is interruptible */ 180 #define SPAGE 0x0000080 /* process in page wait state */ 181 #define SKEEP 0x0000100 /* another flag to prevent swap out */ 182 #define SOMASK 0x0000200 /* restore old mask after taking signal */ 183 #define SWEXIT 0x0000400 /* working on exiting */ 184 #define SPHYSIO 0x0000800 /* doing physical i/o */ 185 #define SVFORK 0x0001000 /* process resulted from vfork() */ 186 #define SVFDONE 0x0002000 /* another vfork flag */ 187 #define SNOVM 0x0004000 /* no vm, parent in a vfork() */ 188 #define SPAGV 0x0008000 /* init data space on demand, from vnode */ 189 #define SSEQL 0x0010000 /* user warned of sequential vm behavior */ 190 #define SUANOM 0x0020000 /* user warned of random vm behavior */ 191 #define STIMO 0x0040000 /* timing out during sleep */ 192 #define SNOCLDSTOP 0x0080000 /* no SIGCHLD when children stop */ 193 #define SCTTY 0x0100000 /* has a controlling terminal */ 194 #define SOWEUPC 0x0200000 /* owe process an addupc() call at next ast */ 195 #define SSEL 0x0400000 /* selecting; wakeup/waiting danger */ 196 #define SEXEC 0x0800000 /* process called exec */ 197 #define SHPUX 0x1000000 /* HP-UX process (HPUXCOMPAT) */ 198 #define SULOCK 0x2000000 /* locked in core after swap error XXX */ 199 #define SPTECHG 0x4000000 /* pte's for process have changed XXX */ 200