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.7 (Berkeley) 01/04/94 8 */ 9 10 #ifndef _SYS_PROC_H_ 11 #define _SYS_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 * 41 * This structure contains the information needed to manage a thread of 42 * control, known in UN*X as a process; it has references to substructures 43 * containing descriptions of things that the process uses, but may share 44 * with related processes. The process structure and the substructures 45 * are always addressible except for those marked "(PROC ONLY)" below, 46 * which might be addressible only on a processor on which the process 47 * is running. 48 */ 49 struct proc { 50 struct proc *p_forw; /* Doubly-linked run/sleep queue. */ 51 struct proc *p_back; 52 struct proc *p_next; /* Linked list of active procs */ 53 struct proc **p_prev; /* and zombies. */ 54 55 /* substructures: */ 56 struct pcred *p_cred; /* Process owner's identity. */ 57 struct filedesc *p_fd; /* Ptr to open files structure. */ 58 struct pstats *p_stats; /* Accounting/statistics (PROC ONLY). */ 59 struct plimit *p_limit; /* Process limits. */ 60 struct vmspace *p_vmspace; /* Address space. */ 61 struct sigacts *p_sigacts; /* Signal actions, state (PROC ONLY). */ 62 63 #define p_ucred p_cred->pc_ucred 64 #define p_rlimit p_limit->pl_rlimit 65 66 int p_flag; /* P_* flags. */ 67 char p_stat; /* S* process status. */ 68 char p_pad1[3]; 69 70 pid_t p_pid; /* Process identifier. */ 71 struct proc *p_hash; /* Hashed based on p_pid for kill+exit+... */ 72 struct proc *p_pgrpnxt; /* Pointer to next process in process group. */ 73 struct proc *p_pptr; /* Pointer to process structure of parent. */ 74 struct proc *p_osptr; /* Pointer to older sibling processes. */ 75 76 /* The following fields are all zeroed upon creation in fork. */ 77 #define p_startzero p_ysptr 78 struct proc *p_ysptr; /* Pointer to younger siblings. */ 79 struct proc *p_cptr; /* Pointer to youngest living child. */ 80 pid_t p_oppid; /* Save parent pid during ptrace. XXX */ 81 int p_dupfd; /* Sideways return value from fdopen. XXX */ 82 83 /* scheduling */ 84 u_int p_estcpu; /* Time averaged value of p_cpticks. */ 85 int p_cpticks; /* Ticks of cpu time. */ 86 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */ 87 void *p_wchan; /* Sleep address. */ 88 char *p_wmesg; /* Reason for sleep. */ 89 u_int p_swtime; /* Time swapped in or out. */ 90 u_int p_slptime; /* Time since last blocked. */ 91 92 struct itimerval p_realtimer; /* Alarm timer. */ 93 struct timeval p_rtime; /* Real time. */ 94 u_quad_t p_uticks; /* Statclock hits in user mode. */ 95 u_quad_t p_sticks; /* Statclock hits in system mode. */ 96 u_quad_t p_iticks; /* Statclock hits processing intr. */ 97 98 int p_traceflag; /* Kernel trace points. */ 99 struct vnode *p_tracep; /* Trace to vnode. */ 100 101 int p_siglist; /* Signals arrived but not delivered. */ 102 103 struct vnode *p_textvp; /* Vnode of executable. */ 104 105 long p_spare[5]; /* pad to 256, avoid shifting eproc. */ 106 107 /* End area that is zeroed on creation. */ 108 #define p_endzero p_startcopy 109 110 /* The following fields are all copied upon creation in fork. */ 111 #define p_startcopy p_sigmask 112 113 sigset_t p_sigmask; /* Current signal mask. */ 114 sigset_t p_sigignore; /* Signals being ignored. */ 115 sigset_t p_sigcatch; /* Signals being caught by user. */ 116 117 u_char p_priority; /* Process priority. */ 118 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */ 119 char p_nice; /* Process "nice" value. */ 120 char p_comm[MAXCOMLEN+1]; 121 122 struct pgrp *p_pgrp; /* Pointer to process group. */ 123 124 /* End area that is copied on creation. */ 125 #define p_endcopy p_thread 126 int p_thread; /* Id for this "thread"; Mach glue. XXX */ 127 struct user *p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */ 128 struct mdproc p_md; /* Any machine-dependent fields. */ 129 130 u_short p_xstat; /* Exit status for wait; also stop signal. */ 131 u_short p_acflag; /* Accounting flags. */ 132 struct rusage *p_ru; /* Exit information. XXX */ 133 134 }; 135 136 #define p_session p_pgrp->pg_session 137 #define p_pgid p_pgrp->pg_id 138 139 /* Status values. */ 140 #define SIDL 1 /* Process being created by fork. */ 141 #define SRUN 2 /* Currently runnable. */ 142 #define SSLEEP 3 /* Sleeping on an address. */ 143 #define SSTOP 4 /* Process debugging or suspension. */ 144 #define SZOMB 5 /* Awaiting collection by parent. */ 145 146 /* These flags are kept in p_flags. */ 147 #define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */ 148 #define P_CONTROLT 0x00002 /* Has a controlling terminal. */ 149 #define P_INMEM 0x00004 /* Loaded into memory. */ 150 #define P_NOCLDSTOP 0x00008 /* No SIGCHLD when children stop. */ 151 #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */ 152 #define P_PROFIL 0x00020 /* Has started profiling. */ 153 #define P_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */ 154 #define P_SINTR 0x00080 /* Sleep is interruptible. */ 155 #define P_SUGID 0x00100 /* Had set id privileges since last exec. */ 156 #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */ 157 #define P_TIMEOUT 0x00400 /* Timing out during sleep. */ 158 #define P_TRACED 0x00800 /* Debugged process being traced. */ 159 #define P_WAITED 0x01000 /* Debugging process has waited for child. */ 160 #define P_WEXIT 0x02000 /* Working on exiting. */ 161 #define P_EXEC 0x04000 /* Process called exec. */ 162 163 /* Should probably be changed into a hold count. */ 164 #define P_NOSWAP 0x08000 /* Another flag to prevent swap out. */ 165 #define P_PHYSIO 0x10000 /* Doing physical I/O. */ 166 167 /* Should be moved to machine-dependent areas. */ 168 #define P_OWEUPC 0x20000 /* Owe process an addupc() call at next ast. */ 169 170 /* 171 * MOVE TO ucred.h? 172 * 173 * Shareable process credentials (always resident). This includes a reference 174 * to the current user credentials as well as real and saved ids that may be 175 * used to change ids. 176 */ 177 struct pcred { 178 struct ucred *pc_ucred; /* Current credentials. */ 179 uid_t p_ruid; /* Real user id. */ 180 uid_t p_svuid; /* Saved effective user id. */ 181 gid_t p_rgid; /* Real group id. */ 182 gid_t p_svgid; /* Saved effective group id. */ 183 int p_refcnt; /* Number of references. */ 184 }; 185 186 #ifdef KERNEL 187 /* 188 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t, 189 * as it is 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 struct proc *pidhash[]; /* In param.c. */ 203 extern struct pgrp *pgrphash[]; /* In param.c. */ 204 extern struct proc *curproc; /* Current running proc. */ 205 extern struct proc proc0; /* Process slot for swapper. */ 206 extern int nprocs, maxproc; /* Current and max number of procs. */ 207 extern int pidhashmask; /* In param.c. */ 208 209 volatile struct proc *allproc; /* List of active procs. */ 210 struct proc *zombproc; /* List of zombie procs. */ 211 struct proc *initproc, *pageproc; /* Process slots for init, pager. */ 212 213 #define NQS 32 /* 32 run queues. */ 214 int whichqs; /* Bit mask summary of non-empty Q's. */ 215 struct prochd { 216 struct proc *ph_link; /* Linked list of running processes. */ 217 struct proc *ph_rlink; 218 } qs[NQS]; 219 220 struct proc *pfind __P((pid_t)); /* Find process by id. */ 221 struct pgrp *pgfind __P((pid_t)); /* Find process group by id. */ 222 223 void mi_switch __P((void)); 224 void resetpriority __P((struct proc *)); 225 void setrunnable __P((struct proc *)); 226 void setrunqueue __P((struct proc *)); 227 void sleep __P((void *chan, int pri)); 228 int tsleep __P((void *chan, int pri, char *wmesg, int timo)); 229 void unsleep __P((struct proc *)); 230 void wakeup __P((void *chan)); 231 #endif /* KERNEL */ 232 #endif /* !_SYS_PROC_H_ */ 233