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