2 * Copyright (c) 1996-1998 University of Utah and the Flux Group.
5 * This file is part of the Flux OSKit. The OSKit is free software, also known
6 * as "open source;" you can redistribute it and/or modify it under the terms
7 * of the GNU General Public License (GPL), version 2, as published by the Free
8 * Software Foundation (FSF). To explore alternate licensing terms, contact
9 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
11 * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
14 * received a copy of the GPL along with the OSKit; see the file COPYING. If
15 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
18 * Copyright (c) 1986, 1989, 1991, 1993
19 * The Regents of the University of California. All rights reserved.
20 * (c) UNIX System Laboratories, Inc.
21 * All or some portions of this file are derived from material licensed
22 * to the University of California by American Telephone and Telegraph
23 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
24 * the permission of UNIX System Laboratories, Inc.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * @(#)proc.h 8.8 (Berkeley) 1/21/94
55 * $\Id: proc.h,v 1.17.4.1 1996/06/04 02:45:01 davidg Exp $
61 #include <machine/proc.h> /* Machine-dependent proc substruct. */
62 #include <sys/rtprio.h> /* For struct rtprio. */
63 #include <sys/select.h> /* For struct selinfo. */
64 #include <sys/time.h> /* For structs itimerval, timeval. */
65 #include <sys/socketvar.h>
68 #include <oskit/dev/dev.h>
72 * One structure allocated per session.
75 int s_count
; /* Ref cnt; pgrps in session. */
76 struct proc
*s_leader
; /* Session leader. */
77 struct vnode
*s_ttyvp
; /* Vnode of controlling terminal. */
78 struct tty
*s_ttyp
; /* Controlling terminal. */
79 char s_login
[MAXLOGNAME
]; /* Setlogin() name. */
83 * One structure allocated per process group.
86 struct pgrp
*pg_hforw
; /* Forward link in hash bucket. */
87 struct proc
*pg_mem
; /* Pointer to pgrp members. */
88 struct session
*pg_session
; /* Pointer to session. */
89 pid_t pg_id
; /* Pgrp id. */
90 int pg_jobc
; /* # procs qualifying pgrp for job control */
94 * Description of a process.
96 * This structure contains the information needed to manage a thread of
97 * control, known in UN*X as a process; it has references to substructures
98 * containing descriptions of things that the process uses, but may share
99 * with related processes. The process structure and the substructures
100 * are always addressible except for those marked "(PROC ONLY)" below,
101 * which might be addressible only on a processor on which the process
106 struct proc
*p_forw
; /* Doubly-linked run/sleep queue. */
108 struct proc
*p_next
; /* Linked list of active procs */
109 struct proc
**p_prev
; /* and zombies. */
112 struct pcred
*p_cred
; /* Process owner's identity. */
113 struct filedesc
*p_fd
; /* Ptr to open files structure. */
114 struct pstats
*p_stats
; /* Accounting/statistics (PROC ONLY). */
115 struct plimit
*p_limit
; /* Process limits. */
116 struct vmspace
*p_vmspace
; /* Address space. */
117 struct sigacts
*p_sigacts
; /* Signal actions, state (PROC ONLY). */
119 #define p_ucred p_cred->pc_ucred
120 #define p_rlimit p_limit->pl_rlimit
122 int p_flag
; /* P_* flags. */
123 char p_stat
; /* S* process status. */
127 pid_t p_pid
; /* Process identifier. */
128 struct proc
*p_hash
; /* Hashed based on p_pid for kill+exit+... */
129 struct proc
*p_pgrpnxt
; /* Pointer to next process in process group. */
130 struct proc
*p_pptr
; /* Pointer to process structure of parent. */
131 struct proc
*p_osptr
; /* Pointer to older sibling processes. */
133 /* The following fields are all zeroed upon creation in fork. */
134 #define p_startzero p_ysptr
135 struct proc
*p_ysptr
; /* Pointer to younger siblings. */
136 struct proc
*p_cptr
; /* Pointer to youngest living child. */
137 pid_t p_oppid
; /* Save parent pid during ptrace. XXX */
138 int p_dupfd
; /* Sideways return value from fdopen. XXX */
141 u_int p_estcpu
; /* Time averaged value of p_cpticks. */
142 int p_cpticks
; /* Ticks of cpu time. */
143 fixpt_t p_pctcpu
; /* %cpu for this process during p_swtime */
144 void *p_wchan
; /* Sleep address. */
145 char *p_wmesg
; /* Reason for sleep. */
146 u_int p_swtime
; /* Time swapped in or out. */
147 u_int p_slptime
; /* Time since last blocked. */
149 struct itimerval p_realtimer
; /* Alarm timer. */
150 struct timeval p_rtime
; /* Real time. */
151 u_quad_t p_uticks
; /* Statclock hits in user mode. */
152 u_quad_t p_sticks
; /* Statclock hits in system mode. */
153 u_quad_t p_iticks
; /* Statclock hits processing intr. */
155 int p_traceflag
; /* Kernel trace points. */
156 struct vnode
*p_tracep
; /* Trace to vnode. */
158 int p_siglist
; /* Signals arrived but not delivered. */
160 struct vnode
*p_textvp
; /* Vnode of executable. */
162 char p_lock
; /* Process lock count. */
163 char p_pad2
[3]; /* alignment */
164 long p_spare
[2]; /* Pad to 256, avoid shifting eproc. XXX */
166 /* End area that is zeroed on creation. */
167 #define p_endzero p_startcopy
169 /* The following fields are all copied upon creation in fork. */
170 #define p_startcopy p_sigmask
172 sigset_t p_sigmask
; /* Current signal mask. */
173 sigset_t p_sigignore
; /* Signals being ignored. */
174 sigset_t p_sigcatch
; /* Signals being caught by user. */
176 u_char p_priority
; /* Process priority. */
177 u_char p_usrpri
; /* User-priority based on p_cpu and p_nice. */
178 char p_nice
; /* Process "nice" value. */
179 char p_comm
[MAXCOMLEN
+1];
181 struct pgrp
*p_pgrp
; /* Pointer to process group. */
183 struct sysentvec
*p_sysent
; /* System call dispatch information. */
185 struct rtprio p_rtprio
; /* Realtime priority. */
186 /* End area that is copied on creation. */
187 #define p_endcopy p_thread
188 int p_thread
; /* Id for this "thread"; Mach glue. XXX */
189 struct user
*p_addr
; /* Kernel virtual addr of u-area (PROC ONLY). */
190 struct mdproc p_md
; /* Any machine-dependent fields. */
192 u_short p_xstat
; /* Exit status for wait; also stop signal. */
193 u_short p_acflag
; /* Accounting flags. */
194 struct rusage
*p_ru
; /* Exit information. XXX */
197 * let's build our own rudimentary struct proc
199 struct proc
*p_forw
; /* Doubly-linked run/sleep queue. */
200 struct pcred
*p_cred
; /* Process owner's identity. */
201 struct pstats
*p_stats
; /* Accounting/statistics (PROC ONLY). */
202 #define p_ucred p_cred->pc_ucred
203 int p_flag
; /* P_* flags. */
204 char p_stat
; /* S* process status. */
205 pid_t p_pid
; /* Process identifier. */
206 void *p_wchan
; /* Sleep address. */
207 char *p_wmesg
; /* Reason for sleep. */
208 u_short p_acflag
; /* Accounting flags. */
210 osenv_sleeprec_t p_sr
;
212 * When selrecord is invoked, this points to an object used to
213 * manage a set of listeners
215 struct listener_mgr
*p_sel
;
219 #define p_session p_pgrp->pg_session
220 #define p_pgid p_pgrp->pg_id
223 #define SIDL 1 /* Process being created by fork. */
224 #define SRUN 2 /* Currently runnable. */
225 #define SSLEEP 3 /* Sleeping on an address. */
226 #define SSTOP 4 /* Process debugging or suspension. */
227 #define SZOMB 5 /* Awaiting collection by parent. */
229 /* These flags are kept in p_flags. */
230 #define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */
231 #define P_CONTROLT 0x00002 /* Has a controlling terminal. */
232 #define P_INMEM 0x00004 /* Loaded into memory. */
233 #define P_NOCLDSTOP 0x00008 /* No SIGCHLD when children stop. */
234 #define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */
235 #define P_PROFIL 0x00020 /* Has started profiling. */
236 #define P_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */
237 #define P_SINTR 0x00080 /* Sleep is interruptible. */
238 #define P_SUGID 0x00100 /* Had set id privileges since last exec. */
239 #define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */
240 #define P_TIMEOUT 0x00400 /* Timing out during sleep. */
241 #define P_TRACED 0x00800 /* Debugged process being traced. */
242 #define P_WAITED 0x01000 /* Debugging process has waited for child. */
243 #define P_WEXIT 0x02000 /* Working on exiting. */
244 #define P_EXEC 0x04000 /* Process called exec. */
245 #define P_SWAPPING 0x40000 /* Process is being swapped. */
247 /* Should probably be changed into a hold count (They have. -DG). */
248 #define P_NOSWAP 0x08000 /* Another flag to prevent swap out. */
249 #define P_PHYSIO 0x10000 /* Doing physical I/O. */
251 /* Should be moved to machine-dependent areas. */
252 #define P_OWEUPC 0x20000 /* Owe process an addupc() call at next ast. */
257 * Shareable process credentials (always resident). This includes a reference
258 * to the current user credentials as well as real and saved ids that may be
259 * used to change ids.
262 struct ucred
*pc_ucred
; /* Current credentials. */
263 uid_t p_ruid
; /* Real user id. */
264 uid_t p_svuid
; /* Saved effective user id. */
265 gid_t p_rgid
; /* Real group id. */
266 gid_t p_svgid
; /* Saved effective group id. */
267 int p_refcnt
; /* Number of references. */
272 * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
273 * as it is used to represent "no process group".
275 #define PID_MAX 30000
277 #define PIDHASH(pid) ((pid) & pidhashmask)
279 #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))
280 #define SESSHOLD(s) ((s)->s_count++)
281 #define SESSRELE(s) { \
282 if (--(s)->s_count == 0) \
283 FREE(s, M_SESSION); \
286 extern struct proc
*pidhash
[]; /* In param.c. */
287 extern struct pgrp
*pgrphash
[]; /* In param.c. */
288 extern struct proc
*curproc
; /* Current running proc. */
289 extern struct proc proc0
; /* Process slot for swapper. */
290 extern int nprocs
, maxproc
; /* Current and max number of procs. */
291 extern int maxprocperuid
; /* Max procs per uid. */
292 extern int pidhashmask
; /* In param.c. */
294 extern volatile struct proc
*allproc
; /* List of active procs. */
295 extern struct proc
*zombproc
; /* List of zombie procs. */
296 extern struct proc
*initproc
, *pageproc
; /* Process slots for init, pager. */
298 #define NQS 32 /* 32 run queues. */
300 struct proc
*ph_link
; /* Linked list of running processes. */
301 struct proc
*ph_rlink
;
303 extern struct prochd qs
[];
304 extern struct prochd rtqs
[];
305 extern struct prochd idqs
[];
306 extern int whichqs
; /* Bit mask summary of non-empty Q's. */
308 int chgproccnt
__P((uid_t
, int));
309 struct proc
*pfind
__P((pid_t
)); /* Find process by id. */
310 struct proc
*zpfind
__P((pid_t
)); /* Find zombie process by id. */
311 struct pgrp
*pgfind
__P((pid_t
)); /* Find process group by id. */
312 void mi_switch
__P((void));
313 void resetpriority
__P((struct proc
*));
314 void roundrobin
__P((void *));
315 void schedcpu
__P((void *));
316 void setrunnable
__P((struct proc
*));
317 void setrunqueue
__P((struct proc
*));
318 void remrq
__P((struct proc
*));
319 void cpu_switch
__P((struct proc
*));
320 void sleep
__P((void *chan
, int pri
));
321 int tsleep
__P((void *chan
, int pri
, char *wmesg
, int timo
));
322 void unsleep
__P((struct proc
*));
323 void wakeup
__P((struct socket
*so
, void *chan
));
325 __dead
void cpu_exit
__P((struct proc
*)) __dead2
;
326 __dead
void exit1
__P((struct proc
*, int)) __dead2
;
327 void fixjobc
__P((struct proc
*, struct pgrp
*, int));
328 int acct_process
__P((struct proc
*));
329 int leavepgrp
__P((struct proc
*));
330 int enterpgrp
__P((struct proc
*, pid_t
, int));
331 int trace_req
__P((struct proc
*));
332 void cpu_wait
__P((struct proc
*));
333 int cpu_coredump
__P((struct proc
*, struct vnode
*, struct ucred
*));
334 int inferior
__P((struct proc
*));
337 #endif /* !_SYS_PROC_H_ */