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