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