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