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