FreeBSD/Linux Kernel Cross Reference
sys/sys/proc.h
1 /*-
2 * Copyright (c) 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)proc.h 8.15 (Berkeley) 5/19/95
39 * $FreeBSD: src/sys/sys/proc.h,v 1.30.2.1 1999/09/05 08:22:44 peter Exp $
40 */
41
42 #ifndef _SYS_PROC_H_
43 #define _SYS_PROC_H_
44
45 #include <machine/proc.h> /* Machine-dependent proc substruct. */
46 #include <sys/rtprio.h> /* For struct rtprio. */
47 #include <sys/select.h> /* For struct selinfo. */
48 #include <sys/time.h> /* For structs itimerval, timeval. */
49 #include <sys/queue.h>
50 #include <sys/param.h>
51
52 /*
53 * One structure allocated per session.
54 */
55 struct session {
56 int s_count; /* Ref cnt; pgrps in session. */
57 struct proc *s_leader; /* Session leader. */
58 struct vnode *s_ttyvp; /* Vnode of controlling terminal. */
59 struct tty *s_ttyp; /* Controlling terminal. */
60 char s_login[MAXLOGNAME]; /* Setlogin() name. */
61 };
62
63 /*
64 * One structure allocated per process group.
65 */
66 struct pgrp {
67 LIST_ENTRY(pgrp) pg_hash; /* Hash chain. */
68 LIST_HEAD(, proc) pg_members; /* Pointer to pgrp members. */
69 struct session *pg_session; /* Pointer to session. */
70 pid_t pg_id; /* Pgrp id. */
71 int pg_jobc; /* # procs qualifying pgrp for job control */
72 };
73
74 /*
75 * Description of a process.
76 *
77 * This structure contains the information needed to manage a thread of
78 * control, known in UN*X as a process; it has references to substructures
79 * containing descriptions of things that the process uses, but may share
80 * with related processes. The process structure and the substructures
81 * are always addressable except for those marked "(PROC ONLY)" below,
82 * which might be addressable only on a processor on which the process
83 * is running.
84 */
85 struct proc {
86 TAILQ_ENTRY(proc) p_procq; /* run/sleep queue. */
87 LIST_ENTRY(proc) p_list; /* List of all processes. */
88
89 /* substructures: */
90 struct pcred *p_cred; /* Process owner's identity. */
91 struct filedesc *p_fd; /* Ptr to open files structure. */
92 struct pstats *p_stats; /* Accounting/statistics (PROC ONLY). */
93 struct plimit *p_limit; /* Process limits. */
94 struct vmspace *p_vmspace; /* Address space. */
95 struct sigacts *p_sigacts; /* Signal actions, state (PROC ONLY). */
96
97 #define p_ucred p_cred->pc_ucred
98 #define p_rlimit p_limit->pl_rlimit
99
100 int p_flag; /* P_* flags. */
101 char p_stat; /* S* process status. */
102 char p_pad1[3];
103
104 pid_t p_pid; /* Process identifier. */
105 LIST_ENTRY(proc) p_pglist; /* List of processes in pgrp. */
106 struct proc *p_pptr; /* Pointer to parent process. */
107 LIST_ENTRY(proc) p_sibling; /* List of sibling processes. */
108 LIST_HEAD(, proc) p_children; /* Pointer to list of children. */
109
110 /* The following fields are all zeroed upon creation in fork. */
111 #define p_startzero p_oppid
112
113 pid_t p_oppid; /* Save parent pid during ptrace. XXX */
114 int p_dupfd; /* Sideways return value from fdopen. XXX */
115
116 /* scheduling */
117 u_int p_estcpu; /* Time averaged value of p_cpticks. */
118 int p_cpticks; /* Ticks of cpu time. */
119 fixpt_t p_pctcpu; /* %cpu for this process during p_swtime */
120 void *p_wchan; /* Sleep address. */
121 char *p_wmesg; /* Reason for sleep. */
122 u_int p_swtime; /* Time swapped in or out. */
123 u_int p_slptime; /* Time since last blocked. */
124
125 struct itimerval p_realtimer; /* Alarm timer. */
126 struct timeval p_rtime; /* Real time. */
127 u_quad_t p_uticks; /* Statclock hits in user mode. */
128 u_quad_t p_sticks; /* Statclock hits in system mode. */
129 u_quad_t p_iticks; /* Statclock hits processing intr. */
130
131 int p_traceflag; /* Kernel trace points. */
132 struct vnode *p_tracep; /* Trace to vnode. */
133
134 int p_siglist; /* Signals arrived but not delivered. */
135
136 struct vnode *p_textvp; /* Vnode of executable. */
137
138 char p_lock; /* Process lock (prevent swap) count. */
139 char p_pad2[3]; /* alignment */
140
141 char *p_selbits; /* For select(), bits */
142 u_int p_selbits_size; /* For select(), fd_set size (bytes) */
143
144 short p_locks; /* DEBUG: lockmgr count of held locks */
145 short p_simple_locks; /* DEBUG: count of held simple locks */
146
147 /* End area that is zeroed on creation. */
148 #define p_endzero p_hash.le_next
149
150 /*
151 * Not copied, not zero'ed.
152 * Belongs after p_pid, but here to avoid shifting proc elements.
153 */
154 LIST_ENTRY(proc) p_hash; /* Hash chain. */
155
156 /* The following fields are all copied upon creation in fork. */
157 #define p_startcopy p_sigmask
158
159 sigset_t p_sigmask; /* Current signal mask. */
160 sigset_t p_sigignore; /* Signals being ignored. */
161 sigset_t p_sigcatch; /* Signals being caught by user. */
162
163 u_char p_priority; /* Process priority. */
164 u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */
165 char p_nice; /* Process "nice" value. */
166 char p_comm[MAXCOMLEN+1];
167
168 struct pgrp *p_pgrp; /* Pointer to process group. */
169
170 struct sysentvec *p_sysent; /* System call dispatch information. */
171
172 struct rtprio p_rtprio; /* Realtime priority. */
173 /* End area that is copied on creation. */
174 #define p_endcopy p_addr
175 struct user *p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
176 struct mdproc p_md; /* Any machine-dependent fields. */
177
178 u_short p_xstat; /* Exit status for wait; also stop signal. */
179 u_short p_acflag; /* Accounting flags. */
180 struct rusage *p_ru; /* Exit information. XXX */
181 };
182
183 #define p_session p_pgrp->pg_session
184 #define p_pgid p_pgrp->pg_id
185
186 /* Status values. */
187 #define SIDL 1 /* Process being created by fork. */
188 #define SRUN 2 /* Currently runnable. */
189 #define SSLEEP 3 /* Sleeping on an address. */
190 #define SSTOP 4 /* Process debugging or suspension. */
191 #define SZOMB 5 /* Awaiting collection by parent. */
192
193 /* These flags are kept in p_flags. */
194 #define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */
195 #define P_CONTROLT 0x00002 /* Has a controlling terminal. */
196 #define P_INMEM 0x00004 /* Loaded into memory. */
197 #define P_NOCLDSTOP 0x00008 /* No SIGCHLD when children stop. */
198 #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */
199 #define P_PROFIL 0x00020 /* Has started profiling. */
200 #define P_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */
201 #define P_SINTR 0x00080 /* Sleep is interruptible. */
202 #define P_SUGID 0x00100 /* Had set id privileges since last exec. */
203 #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */
204 #define P_TIMEOUT 0x00400 /* Timing out during sleep. */
205 #define P_TRACED 0x00800 /* Debugged process being traced. */
206 #define P_WAITED 0x01000 /* Debugging process has waited for child. */
207 #define P_WEXIT 0x02000 /* Working on exiting. */
208 #define P_EXEC 0x04000 /* Process called exec. */
209
210 /* Should probably be changed into a hold count. */
211 #define P_NOSWAP 0x08000 /* Another flag to prevent swap out. */
212 #define P_PHYSIO 0x10000 /* Doing physical I/O. */
213
214 /* Should be moved to machine-dependent areas. */
215 #define P_OWEUPC 0x20000 /* Owe process an addupc() call at next ast. */
216
217 #define P_SWAPPING 0x40000 /* Process is being swapped. */
218 #define P_SWAPINREQ 0x80000 /* Swapin request due to wakeup */
219
220 /*
221 * MOVE TO ucred.h?
222 *
223 * Shareable process credentials (always resident). This includes a reference
224 * to the current user credentials as well as real and saved ids that may be
225 * used to change ids.
226 */
227 struct pcred {
228 struct ucred *pc_ucred; /* Current credentials. */
229 uid_t p_ruid; /* Real user id. */
230 uid_t p_svuid; /* Saved effective user id. */
231 gid_t p_rgid; /* Real group id. */
232 gid_t p_svgid; /* Saved effective group id. */
233 int p_refcnt; /* Number of references. */
234 };
235
236 #ifdef KERNEL
237 /*
238 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
239 * as it is used to represent "no process group".
240 */
241 #define PID_MAX 30000
242 #define NO_PID 30001
243
244 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
245 #define SESSHOLD(s) ((s)->s_count++)
246 #define SESSRELE(s) { \
247 if (--(s)->s_count == 0) \
248 FREE(s, M_SESSION); \
249 }
250
251 /* hold process U-area in memory, normally for ptrace/procfs work */
252 #define PHOLD(p) { \
253 if ((p)->p_lock++ == 0 && ((p)->p_flag & P_INMEM) == 0) \
254 faultin(p); \
255 }
256 #define PRELE(p) (--(p)->p_lock)
257
258 #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
259 extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
260 extern u_long pidhash;
261
262 #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
263 extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
264 extern u_long pgrphash;
265
266 extern struct proc *curproc; /* Current running proc. */
267 extern struct proc proc0; /* Process slot for swapper. */
268 extern int nprocs, maxproc; /* Current and max number of procs. */
269 extern int maxprocperuid; /* Max procs per uid. */
270
271 LIST_HEAD(proclist, proc);
272 extern struct proclist allproc; /* List of all processes. */
273 extern struct proclist zombproc; /* List of zombie processes. */
274 extern struct proc *initproc, *pageproc; /* Process slots for init, pager. */
275
276 #define NQS 32 /* 32 run queues. */
277 extern struct prochd qs[];
278 extern struct prochd rtqs[];
279 extern struct prochd idqs[];
280 extern int whichqs; /* Bit mask summary of non-empty Q's. */
281 struct prochd {
282 struct proc *ph_link; /* Linked list of running processes. */
283 struct proc *ph_rlink;
284 };
285
286 struct proc *pfind __P((pid_t)); /* Find process by id. */
287 struct pgrp *pgfind __P((pid_t)); /* Find process group by id. */
288
289 int chgproccnt __P((uid_t uid, int diff));
290 int enterpgrp __P((struct proc *p, pid_t pgid, int mksess));
291 void fixjobc __P((struct proc *p, struct pgrp *pgrp, int entering));
292 int inferior __P((struct proc *p));
293 int leavepgrp __P((struct proc *p));
294 void mi_switch __P((void));
295 void procinit __P((void));
296 void resetpriority __P((struct proc *));
297 void roundrobin __P((void *));
298 void schedcpu __P((void *));
299 void setrunnable __P((struct proc *));
300 void setrunqueue __P((struct proc *));
301 void sleepinit __P((void));
302 void remrq __P((struct proc *));
303 void cpu_switch __P((struct proc *));
304 void unsleep __P((struct proc *));
305 void wakeup_one __P((void *chan));
306
307 void cpu_exit __P((struct proc *)) __dead2;
308 void exit1 __P((struct proc *, int)) __dead2;
309 int cpu_fork __P((struct proc *, struct proc *));
310 int trace_req __P((struct proc *));
311 void cpu_wait __P((struct proc *));
312 int cpu_coredump __P((struct proc *, struct vnode *, struct ucred *));
313 #endif /* KERNEL */
314
315 #endif /* !_SYS_PROC_H_ */
Cache object: 163b301079304e77c1a3db1a374eee3c
|