xref: /original-bsd/sys/sys/proc.h (revision dd262573)
1 /*
2  * Copyright (c) 1982, 1986, 1989 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.22 (Berkeley) 12/05/90
7  */
8 
9 /*
10  * One structure allocated per session.
11  */
12 struct	session {
13 	int	s_count;	/* ref cnt; pgrps in session */
14 	struct	proc *s_leader;	/* session leader */
15 	struct	vnode *s_ttyvp;	/* vnode of controlling terminal */
16 	struct	tty *s_ttyp;	/* controlling terminal */
17 };
18 
19 /*
20  * One structure allocated per process group.
21  */
22 struct	pgrp {
23 	struct	pgrp *pg_hforw;	/* forward link in hash bucket */
24 	struct	proc *pg_mem;	/* pointer to pgrp members */
25 	struct	session *pg_session;	/* pointer to session */
26 	pid_t	pg_id;		/* pgrp id */
27 	int	pg_jobc;	/* # procs qualifying pgrp for job control */
28 };
29 
30 /*
31  * One structure allocated per active
32  * process. It contains all data needed
33  * about the process while the
34  * process may be swapped out.
35  * Other per process data (user.h)
36  * is swapped with the process.
37  */
38 
39 struct	proc {
40 	struct	proc *p_link;	/* linked list of running processes */
41 	struct	proc *p_rlink;
42 	struct	proc *p_nxt;	/* linked list of allocated proc slots */
43 	struct	proc **p_prev;		/* also zombies, and free proc's */
44 	caddr_t	p_addr;		/* kernel virtual address of u-area */
45 	char	p_usrpri;	/* user-priority based on p_cpu and p_nice */
46 	char	p_pri;		/* priority, negative is high */
47 	char	p_cpu;		/* cpu usage for scheduling */
48 	char	p_stat;
49 	char	p_time;		/* resident time for scheduling */
50 	char	p_nice;		/* nice for cpu usage */
51 	char	p_slptime;	/* time since last block */
52 	char	p_dupfd;	/* sideways return value from fdopen XXX */
53 	int	p_sig;		/* signals pending to this process */
54 	int	p_sigmask;	/* current signal mask */
55 	int	p_sigignore;	/* signals being ignored */
56 	int	p_sigcatch;	/* signals being caught by user */
57 	int	p_flag;
58 	uid_t	p_uid;		/* effective user id */
59 	uid_t	p_ruid;		/* real user id */
60 	uid_t	p_svuid;	/* saved effective user id */
61 	gid_t	p_rgid;		/* real group id */
62 	gid_t	p_svgid;	/* saved effective group id */
63 	pid_t	p_pid;		/* unique process id */
64 	pid_t	p_ppid;		/* process id of parent */
65 	u_short	p_xstat;	/* Exit status for wait; also stop signal */
66 	struct	rusage *p_ru;	/* exit information */
67 	struct	vm_map *p_map;	/* VM address map */
68 	caddr_t	p_shm;		/* SYS5 shared memory private data */
69 	int	p_thread;	/* id for this "thread" (Mach glue) XXX */
70 	int	p_pad1[2];
71 	segsz_t p_rssize; 	/* current resident set size in clicks */
72 	segsz_t p_maxrss;	/* copy of u.u_limit[MAXRSS] */
73 	segsz_t p_swrss;	/* resident set size before last swap */
74 	swblk_t	p_swaddr;	/* disk address of u area when swapped */
75 	caddr_t p_wchan;	/* event process is awaiting */
76 	int	pad2[3];
77 	int	p_cpticks;	/* ticks of cpu time */
78 	fixpt_t	p_pctcpu;	/* %cpu for this process during p_time */
79 	short	p_ndx;		/* proc index for memall (because of vfork) */
80 	struct	proc *p_hash;	/* hashed based on p_pid for kill+exit+... */
81 	struct	proc *p_pptr;	/* pointer to process structure of parent */
82 	struct	proc *p_cptr;	/* pointer to youngest living child */
83 	struct	proc *p_osptr;	/* pointer to older sibling processes */
84 	struct	proc *p_ysptr;	/* pointer to younger siblings */
85 	struct 	pgrp *p_pgrp;	/* pointer to process group */
86 #define p_session p_pgrp->pg_session
87 #define p_pgid	p_pgrp->pg_id
88 	struct	proc *p_pgrpnxt; /* pointer to next process in process group */
89 	struct	itimerval p_realtimer;
90 	int	p_traceflag;	/* kernel trace points */
91 	struct	vnode *p_tracep;/* trace to vnode */
92 	char	p_comm[MAXCOMLEN+1];
93 	char	p_logname[MAXLOGNAME];
94 	char	*p_wmesg;
95 	struct	timeval p_utime; /* user time */
96 	struct	timeval p_stime; /* system time */
97 #if defined(tahoe)
98 	int	p_ckey;		/* code cache key */
99 	int	p_dkey;		/* data cache key */
100 #endif
101 };
102 
103 /*
104  * proc ops return arrays of augmented proc structures
105  */
106 struct kinfo_proc {
107 	struct	proc kp_proc;			/* proc structure */
108 	struct	eproc {
109 		struct	proc *e_paddr;		/* address of proc */
110 		struct	session *e_sess;	/* session pointer */
111 		pid_t	e_pgid;			/* process group id */
112 		short	e_jobc;			/* job control counter */
113 		dev_t	e_tdev;			/* controlling tty dev */
114 		pid_t	e_tpgid;		/* tty process group id */
115 		struct	session *e_tsess;	/* tty session pointer */
116 #define	WMESGLEN	7
117 		char	e_wmesg[WMESGLEN+1];	/* wchan message */
118 		segsz_t e_xsize;		/* text size */
119 		short	e_xrssize;		/* text rss */
120 		short	e_xccount;		/* text references */
121 		short	e_xswrss;
122 		long	e_flag;
123 #define	EPROC_CTTY	0x01	/* controlling tty vnode active */
124 #define	EPROC_SLEADER	0x02	/* session leader */
125 		long	e_spare[7];
126 	} kp_eproc;
127 };
128 
129 #ifdef KERNEL
130 /*
131  * We use process IDs <= PID_MAX;
132  * PID_MAX + 1 must also fit in a pid_t
133  * (used to represent "no process group").
134  */
135 #define	PID_MAX		30000
136 #define	NO_PID		30001
137 #define	PIDHASH(pid)	((pid) & pidhashmask)
138 extern	int pidhashmask;		/* in param.c */
139 extern	struct proc *pidhash[];		/* in param.c */
140 struct	proc *pfind();			/* find process by id */
141 extern	struct pgrp *pgrphash[];	/* in param.c */
142 struct 	pgrp *pgfind();			/* find process group by id */
143 struct	proc *proc, *procNPROC;		/* the proc table itself */
144 struct	proc *freeproc, *zombproc, *allproc;
145 					/* lists of procs in various states */
146 int	nproc;
147 
148 #define	NQS	32		/* 32 run queues */
149 struct	prochd {
150 	struct	proc *ph_link;	/* linked list of running processes */
151 	struct	proc *ph_rlink;
152 } qs[NQS];
153 int	whichqs;		/* bit mask summarizing non-empty qs's */
154 
155 #define SESS_LEADER(p)	((p)->p_session->s_leader == (p))
156 #define	SESSHOLD(s)	((s)->s_count++)
157 #define	SESSRELE(s)	{ \
158 		if (--(s)->s_count == 0) \
159 			FREE(s, M_SESSION); \
160 		}
161 #endif
162 
163 /* stat codes */
164 #define	SSLEEP	1		/* awaiting an event */
165 #define	SWAIT	2		/* (abandoned state) */
166 #define	SRUN	3		/* running */
167 #define	SIDL	4		/* intermediate state in process creation */
168 #define	SZOMB	5		/* intermediate state in process termination */
169 #define	SSTOP	6		/* process being traced */
170 
171 /* flag codes */
172 #define	SLOAD	0x0000001	/* in core */
173 #define	SSYS	0x0000002	/* swapper or pager process */
174 #define	SLOCK	0x0000004	/* process being swapped out */
175 #define	SSWAP	0x0000008	/* save area flag */
176 #define	STRC	0x0000010	/* process is being traced */
177 #define	SWTED	0x0000020	/* another tracing flag */
178 #define	SSINTR	0x0000040	/* sleep is interruptible */
179 #define	SPAGE	0x0000080	/* process in page wait state */
180 #define	SKEEP	0x0000100	/* another flag to prevent swap out */
181 #define	SOMASK	0x0000200	/* restore old mask after taking signal */
182 #define	SWEXIT	0x0000400	/* working on exiting */
183 #define	SPHYSIO	0x0000800	/* doing physical i/o */
184 #define	SVFORK	0x0001000	/* process resulted from vfork() */
185 #define	SVFDONE	0x0002000	/* another vfork flag */
186 #define	SNOVM	0x0004000	/* no vm, parent in a vfork() */
187 #define	SPAGV	0x0008000	/* init data space on demand, from vnode */
188 #define	SSEQL	0x0010000	/* user warned of sequential vm behavior */
189 #define	SUANOM	0x0020000	/* user warned of random vm behavior */
190 #define	STIMO	0x0040000	/* timing out during sleep */
191 #define	SNOCLDSTOP 0x0080000	/* no SIGCHLD when children stop */
192 #define	SCTTY	0x0100000	/* has a controlling terminal */
193 #define	SOWEUPC	0x0200000	/* owe process an addupc() call at next ast */
194 #define	SSEL	0x0400000	/* selecting; wakeup/waiting danger */
195 #define SEXEC	0x0800000	/* process called exec */
196 #define	SHPUX	0x1000000	/* HP-UX process (HPUXCOMPAT) */
197 #define	SULOCK	0x2000000	/* locked in core after swap error XXX */
198 #define	SPTECHG	0x4000000	/* pte's for process have changed XXX */
199