1 /* 2 * Copyright (c) 1982, 1986, 1989, 1991 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.25 (Berkeley) 04/20/91 7 */ 8 9 #ifndef _PROC_H_ 10 #define _PROC_H_ 11 12 #include <machine/proc.h> /* machine-dependent proc substruct */ 13 14 /* 15 * One structure allocated per session. 16 */ 17 struct session { 18 int s_count; /* ref cnt; pgrps in session */ 19 struct proc *s_leader; /* session leader */ 20 struct vnode *s_ttyvp; /* vnode of controlling terminal */ 21 struct tty *s_ttyp; /* controlling terminal */ 22 char s_login[MAXLOGNAME]; /* setlogin() name */ 23 }; 24 25 /* 26 * One structure allocated per process group. 27 */ 28 struct pgrp { 29 struct pgrp *pg_hforw; /* forward link in hash bucket */ 30 struct proc *pg_mem; /* pointer to pgrp members */ 31 struct session *pg_session; /* pointer to session */ 32 pid_t pg_id; /* pgrp id */ 33 int pg_jobc; /* # procs qualifying pgrp for job control */ 34 }; 35 36 /* 37 * Description of a process. 38 * This structure contains the information needed to manage a thread 39 * of control, known in UN*X as a process; it has references to substructures 40 * containing descriptions of things that the process uses, but may share 41 * with related processes. The process structure and the substructures 42 * are always addressible except for those marked "(proc only)" below, 43 * which might be addressible only on a processor on which the process 44 * is running. 45 */ 46 struct proc { 47 struct proc *p_link; /* doubly-linked run/sleep queue */ 48 struct proc *p_rlink; 49 struct proc *p_nxt; /* linked list of active procs */ 50 struct proc **p_prev; /* and zombies */ 51 52 /* substructures: */ 53 struct pcred *p_cred; /* process owner's identity */ 54 struct filedesc *p_fd; /* ptr to open files structure */ 55 struct pstats *p_stats; /* accounting/statistics (proc only) */ 56 struct plimit *p_limit; /* process limits */ 57 struct vmspace *p_vmspace; /* address space */ 58 struct sigacts *p_sigacts; /* signal actions, state (proc only) */ 59 60 #define p_ucred p_cred->pc_ucred 61 #define p_rlimit p_limit->pl_rlimit 62 63 int p_flag; 64 char p_stat; 65 /* char p_space; */ 66 67 pid_t p_pid; /* unique process id */ 68 struct proc *p_hash; /* hashed based on p_pid for kill+exit+... */ 69 struct proc *p_pgrpnxt; /* pointer to next process in process group */ 70 struct proc *p_pptr; /* pointer to process structure of parent */ 71 struct proc *p_osptr; /* pointer to older sibling processes */ 72 73 /* The following fields are all zeroed upon creation in fork */ 74 #define p_startzero p_ysptr 75 struct proc *p_ysptr; /* pointer to younger siblings */ 76 struct proc *p_cptr; /* pointer to youngest living child */ 77 78 /* scheduling */ 79 u_int p_cpu; /* cpu usage for scheduling */ 80 int p_cpticks; /* ticks of cpu time */ 81 fixpt_t p_pctcpu; /* %cpu for this process during p_time */ 82 caddr_t p_wchan; /* event process is awaiting */ 83 u_int p_time; /* resident/nonresident time for swapping */ 84 u_int p_slptime; /* time since last block */ 85 86 struct itimerval p_realtimer; /* alarm timer */ 87 struct timeval p_utime; /* user time */ 88 struct timeval p_stime; /* system time */ 89 90 int p_traceflag; /* kernel trace points */ 91 struct vnode *p_tracep;/* trace to vnode */ 92 93 int p_sig; /* signals pending to this process */ 94 95 /* end area that is zeroed on creation */ 96 #define p_endzero p_startcopy 97 98 /* The following fields are all copied upon creation in fork */ 99 sigset_t p_sigmask; /* current signal mask */ 100 #define p_startcopy p_sigmask 101 sigset_t p_sigignore; /* signals being ignored */ 102 sigset_t p_sigcatch; /* signals being caught by user */ 103 104 u_char p_pri; /* priority, negative is high */ 105 u_char p_usrpri; /* user-priority based on p_cpu and p_nice */ 106 char p_nice; /* nice for cpu usage */ 107 /* char p_space1; */ 108 109 struct pgrp *p_pgrp; /* pointer to process group */ 110 char p_comm[MAXCOMLEN+1]; 111 112 /* end area that is copied on creation */ 113 #define p_endcopy p_wmesg 114 char *p_wmesg; /* reason for sleep */ 115 int p_thread; /* id for this "thread" (Mach glue) XXX */ 116 caddr_t p_addr; /* kernel virtual address of u-area */ 117 swblk_t p_swaddr; /* disk address of u area when swapped */ 118 int *p_regs; /* saved registers during syscall/trap */ 119 struct mdproc p_md; /* any machine-dependent fields */ 120 121 u_short p_xstat; /* Exit status for wait; also stop signal */ 122 u_short p_dupfd; /* sideways return value from fdopen XXX */ 123 u_short p_acflag; /* accounting flags */ 124 /* short p_space2; */ 125 struct rusage *p_ru; /* exit information XXX */ 126 127 long p_spare[4]; /* tmp spares to avoid shifting eproc */ 128 }; 129 130 #define p_session p_pgrp->pg_session 131 #define p_pgid p_pgrp->pg_id 132 133 /* MOVE TO ucred.h? */ 134 /* 135 * Shareable process credentials (always resident). 136 * This includes a reference to the current user credentials 137 * as well as real and saved ids that may be used to change ids. 138 */ 139 struct pcred { 140 struct ucred *pc_ucred; /* current credentials */ 141 uid_t p_ruid; /* real user id */ 142 uid_t p_svuid; /* saved effective user id */ 143 gid_t p_rgid; /* real group id */ 144 gid_t p_svgid; /* saved effective group id */ 145 int p_refcnt; /* number of references */ 146 }; 147 148 /* stat codes */ 149 #define SSLEEP 1 /* awaiting an event */ 150 #define SWAIT 2 /* (abandoned state) */ 151 #define SRUN 3 /* running */ 152 #define SIDL 4 /* intermediate state in process creation */ 153 #define SZOMB 5 /* intermediate state in process termination */ 154 #define SSTOP 6 /* process being traced */ 155 156 /* flag codes */ 157 #define SLOAD 0x0000001 /* in core */ 158 #define SSYS 0x0000002 /* swapper or pager process */ 159 #define SSINTR 0x0000004 /* sleep is interruptible */ 160 #define SCTTY 0x0000008 /* has a controlling terminal */ 161 #define SPPWAIT 0x0000010 /* parent is waiting for child to exec/exit */ 162 #define SEXEC 0x0000020 /* process called exec */ 163 #define STIMO 0x0000040 /* timing out during sleep */ 164 #define SSEL 0x0000080 /* selecting; wakeup/waiting danger */ 165 #define SWEXIT 0x0000100 /* working on exiting */ 166 #define SNOCLDSTOP 0x0000200 /* no SIGCHLD when children stop */ 167 /* the following three should probably be changed into a hold count */ 168 #define SLOCK 0x0000400 /* process being swapped out */ 169 #define SKEEP 0x0000800 /* another flag to prevent swap out */ 170 #define SPHYSIO 0x0001000 /* doing physical i/o */ 171 #define STRC 0x0004000 /* process is being traced */ 172 #define SWTED 0x0008000 /* another tracing flag */ 173 /* the following should be moved to machine-dependent areas */ 174 #define SOWEUPC 0x0002000 /* owe process an addupc() call at next ast */ 175 #ifdef HPUXCOMPAT 176 #define SHPUX 0x0010000 /* HP-UX process (HPUXCOMPAT) */ 177 #else 178 #define SHPUX 0 /* not HP-UX process (HPUXCOMPAT) */ 179 #endif 180 /* not currently in use (never set) */ 181 #define SPAGE 0x0020000 /* process in page wait state */ 182 183 #ifdef KERNEL 184 /* 185 * We use process IDs <= PID_MAX; 186 * PID_MAX + 1 must also fit in a pid_t 187 * (used to represent "no process group"). 188 */ 189 #define PID_MAX 30000 190 #define NO_PID 30001 191 #define PIDHASH(pid) ((pid) & pidhashmask) 192 193 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p)) 194 #define SESSHOLD(s) ((s)->s_count++) 195 #define SESSRELE(s) { \ 196 if (--(s)->s_count == 0) \ 197 FREE(s, M_SESSION); \ 198 } 199 200 extern int pidhashmask; /* in param.c */ 201 extern struct proc *pidhash[]; /* in param.c */ 202 struct proc *pfind(); /* find process by id */ 203 extern struct pgrp *pgrphash[]; /* in param.c */ 204 struct pgrp *pgfind(); /* find process group by id */ 205 struct proc *zombproc, *allproc; /* lists of procs in various states */ 206 extern struct proc proc0; /* process slot for swapper */ 207 struct proc *initproc, *pageproc; /* process slots for init, pager */ 208 extern struct proc *curproc; /* current running proc */ 209 extern int nprocs, maxproc; /* current and max number of procs */ 210 211 #define NQS 32 /* 32 run queues */ 212 struct prochd { 213 struct proc *ph_link; /* linked list of running processes */ 214 struct proc *ph_rlink; 215 } qs[NQS]; 216 217 int whichqs; /* bit mask summarizing non-empty qs's */ 218 #endif /* KERNEL */ 219 220 #endif /* !_PROC_H_ */ 221