xref: /original-bsd/sys/sys/proc.h (revision 7c3db03c)
1 /*
2  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)proc.h	7.24 (Berkeley) 03/17/91
7  */
8 
9 #include "vm/vm.h"			/* XXX */
10 
11 /*
12  * One structure allocated per session.
13  */
14 struct	session {
15 	int	s_count;		/* ref cnt; pgrps in session */
16 	struct	proc *s_leader;		/* session leader */
17 	struct	vnode *s_ttyvp;		/* vnode of controlling terminal */
18 	struct	tty *s_ttyp;		/* controlling terminal */
19 	char	s_login[MAXLOGNAME];	/* setlogin() name */
20 };
21 
22 /*
23  * One structure allocated per process group.
24  */
25 struct	pgrp {
26 	struct	pgrp *pg_hforw;		/* forward link in hash bucket */
27 	struct	proc *pg_mem;		/* pointer to pgrp members */
28 	struct	session *pg_session;	/* pointer to session */
29 	pid_t	pg_id;			/* pgrp id */
30 	int	pg_jobc;	/* # procs qualifying pgrp for job control */
31 };
32 
33 /*
34  * Description of a process.
35  * This structure contains the information needed to manage a thread
36  * of control, known in UN*X as a process; it has references to substructures
37  * containing descriptions of things that the process uses, but may share
38  * with related processes.  The process structure and the substructures
39  * are always addressible except for those marked "(proc only)" below,
40  * which might be addressible only on a processor on which the process
41  * is running.
42  */
43 struct	proc {
44 	struct	proc *p_link;		/* doubly-linked run/sleep queue */
45 	struct	proc *p_rlink;
46 	struct	proc *p_nxt;		/* linked list of active procs */
47 	struct	proc **p_prev;		/*    and zombies */
48 
49 	/* substructures: */
50 	struct	pcred *p_cred;		/* process owner's identity */
51 	struct	filedesc *p_fd;		/* ptr to open files structure */
52 	struct	pstats *p_stats;	/* accounting/statistics (proc only) */
53 	struct	plimit *p_limit;	/* process limits */
54 	struct	vmspace *p_vmspace;	/* address space */
55 	struct	sigacts *p_sigacts;	/* signal actions, state (proc only) */
56 
57 #define	p_ucred		p_cred->pc_ucred
58 #define	p_rlimit	p_limit->pl_rlimit
59 
60 	int	p_flag;
61 	char	p_stat;
62 /*	char	p_space; */
63 
64 	pid_t	p_pid;		/* unique process id */
65 	struct	proc *p_hash;	/* hashed based on p_pid for kill+exit+... */
66 	struct	proc *p_pgrpnxt; /* pointer to next process in process group */
67 	struct	proc *p_pptr;	/* pointer to process structure of parent */
68 	struct	proc *p_osptr;	/* pointer to older sibling processes */
69 
70 /* The following fields are all zeroed upon creation in fork */
71 #define	p_startzero	p_ysptr
72 	struct	proc *p_ysptr;	/* pointer to younger siblings */
73 	struct	proc *p_cptr;	/* pointer to youngest living child */
74 
75 	/* scheduling */
76 	u_int	p_cpu;		/* cpu usage for scheduling */
77 	int	p_cpticks;	/* ticks of cpu time */
78 	fixpt_t	p_pctcpu;	/* %cpu for this process during p_time */
79 	caddr_t p_wchan;	/* event process is awaiting */
80 	u_int	p_time;		/* resident/nonresident time for swapping */
81 	u_int	p_slptime;	/* time since last block */
82 
83 	struct	itimerval p_realtimer;	/* alarm timer */
84 	struct	timeval p_utime;	/* user time */
85 	struct	timeval p_stime;	/* system time */
86 
87 	int	p_traceflag;	/* kernel trace points */
88 	struct	vnode *p_tracep;/* trace to vnode */
89 
90 	int	p_sig;		/* signals pending to this process */
91 
92 /* end area that is zeroed on creation */
93 #define	p_endzero	p_startcopy
94 
95 /* The following fields are all copied upon creation in fork */
96 	sigset_t p_sigmask;	/* current signal mask */
97 #define	p_startcopy	p_sigmask
98 	sigset_t p_sigignore;	/* signals being ignored */
99 	sigset_t p_sigcatch;	/* signals being caught by user */
100 
101 	u_char	p_pri;		/* priority, negative is high */
102 	u_char	p_usrpri;	/* user-priority based on p_cpu and p_nice */
103 	char	p_nice;		/* nice for cpu usage */
104 /*	char	p_space; */
105 
106 	struct 	pgrp *p_pgrp;	/* pointer to process group */
107 	char	p_comm[MAXCOMLEN+1];
108 
109 /* end area that is copied on creation */
110 #define	p_endcopy	p_wmesg
111 	char	*p_wmesg;	/* reason for sleep */
112 	int	p_thread;	/* id for this "thread" (Mach glue) XXX */
113 	caddr_t	p_addr;		/* kernel virtual address of u-area */
114 	swblk_t	p_swaddr;	/* disk address of u area when swapped */
115 	int	*p_regs;	/* saved registers during syscall/trap */
116 
117 	u_short	p_xstat;	/* Exit status for wait; also stop signal */
118 	u_short	p_dupfd;	/* sideways return value from fdopen XXX */
119 	u_short	p_acflag;	/* accounting flags */
120 /*	u_short	p_space; */
121 	struct	rusage *p_ru;	/* exit information XXX */
122 
123 	long	p_spare[4];	/* tmp spares to avoid shifting eproc */
124 };
125 
126 #define	p_session	p_pgrp->pg_session
127 #define	p_pgid		p_pgrp->pg_id
128 
129 /* MOVE TO ucred.h? */
130 /*
131  * Shareable process credentials (always resident).
132  * This includes a reference to the current user credentials
133  * as well as real and saved ids that may be used to change ids.
134  */
135 struct	pcred {
136 	struct	ucred *pc_ucred;	/* current credentials */
137 	uid_t	p_ruid;			/* real user id */
138 	uid_t	p_svuid;		/* saved effective user id */
139 	gid_t	p_rgid;			/* real group id */
140 	gid_t	p_svgid;		/* saved effective group id */
141 	int	p_refcnt;		/* number of references */
142 };
143 
144 /*
145  * getkerninfo() proc ops return arrays of augmented proc structures:
146  */
147 struct kinfo_proc {
148 	struct	proc kp_proc;			/* proc structure */
149 	struct	eproc {
150 		struct	proc *e_paddr;		/* address of proc */
151 		struct	session *e_sess;	/* session pointer */
152 		struct	pcred e_pcred;		/* process credentials */
153 		struct	ucred e_ucred;		/* current credentials */
154 		struct	vmspace e_vm;		/* address space */
155 		pid_t	e_pgid;			/* process group id */
156 		short	e_jobc;			/* job control counter */
157 		dev_t	e_tdev;			/* controlling tty dev */
158 		pid_t	e_tpgid;		/* tty process group id */
159 		struct	session *e_tsess;	/* tty session pointer */
160 #define	WMESGLEN	7
161 		char	e_wmesg[WMESGLEN+1];	/* wchan message */
162 		segsz_t e_xsize;		/* text size */
163 		short	e_xrssize;		/* text rss */
164 		short	e_xccount;		/* text references */
165 		short	e_xswrss;
166 		long	e_flag;
167 #define	EPROC_CTTY	0x01	/* controlling tty vnode active */
168 #define	EPROC_SLEADER	0x02	/* session leader */
169 		long	e_spare[7];
170 	} kp_eproc;
171 };
172 
173 #ifdef KERNEL
174 /*
175  * We use process IDs <= PID_MAX;
176  * PID_MAX + 1 must also fit in a pid_t
177  * (used to represent "no process group").
178  */
179 #define	PID_MAX		30000
180 #define	NO_PID		30001
181 #define	PIDHASH(pid)	((pid) & pidhashmask)
182 extern	int pidhashmask;		/* in param.c */
183 extern	struct proc *pidhash[];		/* in param.c */
184 struct	proc *pfind();			/* find process by id */
185 extern	struct pgrp *pgrphash[];	/* in param.c */
186 struct 	pgrp *pgfind();			/* find process group by id */
187 struct	proc *zombproc, *allproc;
188 extern	struct proc proc0;		/* process slot for swapper */
189 struct	proc *initproc, *pageproc;	/* process slots for init, pager */
190 #ifdef notyet
191 struct	proc *curproc;			/* current running proc */
192 #endif
193 					/* lists of procs in various states */
194 extern	int nprocs, maxproc;		/* current and max number of procs */
195 
196 #define	NQS	32		/* 32 run queues */
197 struct	prochd {
198 	struct	proc *ph_link;	/* linked list of running processes */
199 	struct	proc *ph_rlink;
200 } qs[NQS];
201 
202 int	whichqs;		/* bit mask summarizing non-empty qs's */
203 
204 #define SESS_LEADER(p)	((p)->p_session->s_leader == (p))
205 #define	SESSHOLD(s)	((s)->s_count++)
206 #define	SESSRELE(s)	{ \
207 		if (--(s)->s_count == 0) \
208 			FREE(s, M_SESSION); \
209 		}
210 #endif
211 
212 /* stat codes */
213 #define	SSLEEP	1		/* awaiting an event */
214 #define	SWAIT	2		/* (abandoned state) */
215 #define	SRUN	3		/* running */
216 #define	SIDL	4		/* intermediate state in process creation */
217 #define	SZOMB	5		/* intermediate state in process termination */
218 #define	SSTOP	6		/* process being traced */
219 
220 /* flag codes */
221 /* NEED TO CHECK which of these are still used */
222 #define	SLOAD	0x0000001	/* in core */
223 #define	SSYS	0x0000002	/* swapper or pager process */
224 #define	SLOCK	0x0000004	/* process being swapped out */
225 #define	SSWAP	0x0000008	/* save area flag */
226 #define	STRC	0x0000010	/* process is being traced */
227 #define	SWTED	0x0000020	/* another tracing flag */
228 #define	SSINTR	0x0000040	/* sleep is interruptible */
229 #define	SPAGE	0x0000080	/* process in page wait state */
230 #define	SKEEP	0x0000100	/* another flag to prevent swap out */
231 /*#define SOMASK	0x0000200	/* restore old mask after taking signal */
232 #define	SWEXIT	0x0000400	/* working on exiting */
233 #define	SPHYSIO	0x0000800	/* doing physical i/o */
234 #define	SPPWAIT	0x0001000	/* parent is waiting for child to exec/exit */
235 #define	SVFORK	SPARSYNC	/* process resulted from vfork() XXX */
236 /*#define SVFDONE	0x0002000	/* another vfork flag XXX */
237 /*#define SNOVM	0x0004000	/* no vm, parent in a vfork() XXX */
238 #define	SPAGV	0x0008000	/* init data space on demand, from vnode */
239 #define	SSEQL	0x0010000	/* user warned of sequential vm behavior */
240 #define	SUANOM	0x0020000	/* user warned of random vm behavior */
241 #define	STIMO	0x0040000	/* timing out during sleep */
242 #define	SNOCLDSTOP 0x0080000	/* no SIGCHLD when children stop */
243 #define	SCTTY	0x0100000	/* has a controlling terminal */
244 #define	SOWEUPC	0x0200000	/* owe process an addupc() call at next ast */
245 #define	SSEL	0x0400000	/* selecting; wakeup/waiting danger */
246 #define SEXEC	0x0800000	/* process called exec */
247 #define	SHPUX	0x1000000	/* HP-UX process (HPUXCOMPAT) */
248 #define	SULOCK	0x2000000	/* locked in core after swap error XXX */
249 #define	SPTECHG	0x4000000	/* pte's for process have changed XXX */
250