1 /* 2 * Copyright (c) 1982, 1986 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.3 (Berkeley) 10/18/88 7 */ 8 9 /* 10 * One structure allocated per session. 11 */ 12 struct session { 13 struct proc *s_leader; /* pointer to session leader */ 14 short 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; /* user id, used to direct tty signals */ 56 pid_t p_pid; /* unique process id */ 57 pid_t p_ppid; /* process id of parent */ 58 u_short p_xstat; /* Exit status for wait */ 59 struct rusage *p_ru; /* mbuf holding exit information */ 60 short p_poip; /* page outs in progress */ 61 short p_szpt; /* copy of page table size */ 62 size_t p_tsize; /* size of text (clicks) */ 63 size_t p_dsize; /* size of data space (clicks) */ 64 size_t p_ssize; /* copy of stack size (clicks) */ 65 size_t p_rssize; /* current resident set size in clicks */ 66 size_t p_maxrss; /* copy of u.u_limit[MAXRSS] */ 67 size_t p_swrss; /* resident set size before last swap */ 68 swblk_t p_swaddr; /* disk address of u area when swapped */ 69 caddr_t p_wchan; /* event process is awaiting */ 70 struct text *p_textp; /* pointer to text structure */ 71 struct pte *p_p0br; /* page table base P0BR */ 72 struct proc *p_xlink; /* linked list of procs sharing same text */ 73 short p_cpticks; /* ticks of cpu time */ 74 float p_pctcpu; /* %cpu for this process during p_time */ 75 short p_ndx; /* proc index for memall (because of vfork) */ 76 short p_idhash; /* hashed based on p_pid for kill+exit+... */ 77 struct proc *p_pptr; /* pointer to process structure of parent */ 78 struct proc *p_cptr; /* pointer to youngest living child */ 79 struct proc *p_osptr; /* pointer to older sibling processes */ 80 struct proc *p_ysptr; /* pointer to younger siblings */ 81 struct pgrp *p_pgrp; /* pointer to process group */ 82 #define p_session p_pgrp->pg_session 83 #define p_pgid p_pgrp->pg_id 84 struct proc *p_pgrpnxt; /* pointer to next process in process group */ 85 struct itimerval p_realtimer; 86 struct quota *p_quota; /* quotas for this process */ 87 #if defined(tahoe) 88 int p_ckey; /* code cache key */ 89 int p_dkey; /* data cache key */ 90 #endif 91 }; 92 93 #define PIDHSZ 64 94 #define PIDHASH(pid) ((pid) & (PIDHSZ - 1)) 95 96 #ifdef KERNEL 97 pid_t pidhash[PIDHSZ]; 98 struct proc *pfind(); 99 struct pgrp *pgrphash[PIDHSZ]; 100 struct pgrp *pgfind(); /* find process group by id */ 101 struct proc *proc, *procNPROC; /* the proc table itself */ 102 struct proc *freeproc, *zombproc, *allproc; 103 /* lists of procs in various states */ 104 int nproc; 105 106 #define NQS 32 /* 32 run queues */ 107 struct prochd { 108 struct proc *ph_link; /* linked list of running processes */ 109 struct proc *ph_rlink; 110 } qs[NQS]; 111 int whichqs; /* bit mask summarizing non-empty qs's */ 112 113 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p)) 114 #define PGRP_JOBC(p) (((p)->p_pgrp != (p)->p_pptr->p_pgrp) && \ 115 ((p)->p_session == (p)->p_pptr->p_session)) 116 #endif 117 118 /* stat codes */ 119 #define SSLEEP 1 /* awaiting an event */ 120 #define SWAIT 2 /* (abandoned state) */ 121 #define SRUN 3 /* running */ 122 #define SIDL 4 /* intermediate state in process creation */ 123 #define SZOMB 5 /* intermediate state in process termination */ 124 #define SSTOP 6 /* process being traced */ 125 126 /* flag codes */ 127 #define SLOAD 0x0000001 /* in core */ 128 #define SSYS 0x0000002 /* swapper or pager process */ 129 #define SLOCK 0x0000004 /* process being swapped out */ 130 #define SSWAP 0x0000008 /* save area flag */ 131 #define STRC 0x0000010 /* process is being traced */ 132 #define SWTED 0x0000020 /* another tracing flag */ 133 #define SULOCK 0x0000040 /* user settable lock in core */ 134 #define SPAGE 0x0000080 /* process in page wait state */ 135 #define SKEEP 0x0000100 /* another flag to prevent swap out */ 136 #define SOMASK 0x0000200 /* restore old mask after taking signal */ 137 #define SWEXIT 0x0000400 /* working on exiting */ 138 #define SPHYSIO 0x0000800 /* doing physical i/o (bio.c) */ 139 #define SVFORK 0x0001000 /* process resulted from vfork() */ 140 #define SVFDONE 0x0002000 /* another vfork flag */ 141 #define SNOVM 0x0004000 /* no vm, parent in a vfork() */ 142 #define SPAGI 0x0008000 /* init data space on demand, from inode */ 143 #define SSEQL 0x0010000 /* user warned of sequential vm behavior */ 144 #define SUANOM 0x0020000 /* user warned of random vm behavior */ 145 #define STIMO 0x0040000 /* timing out during sleep */ 146 /* was SDETACH */ 147 #define SOUSIG 0x0100000 /* using old signal mechanism */ 148 #define SOWEUPC 0x0200000 /* owe process an addupc() call at next ast */ 149 #define SSEL 0x0400000 /* selecting; wakeup/waiting danger */ 150 #define SLOGIN 0x0800000 /* a login process (legit child of init) */ 151 #define SPTECHG 0x1000000 /* pte's for process have changed */ 152 #define STRCSYS 0x2000000 /* tracing system calls */ 153 #define STRCSYSI 0x4000000 /* tracing system calls - inherited */ 154 #define SEXEC 0x8000000 /* process called exec */ 155