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