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