xref: /csrg-svn/sys/kern/kern_proc.c (revision 25385)
1 /*
2  * Copyright (c) 1982 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  *	@(#)kern_proc.c	6.7 (Berkeley) 11/04/85
7  */
8 
9 #include "../machine/reg.h"
10 #include "../machine/pte.h"
11 #include "../machine/psl.h"
12 
13 #include "param.h"
14 #include "systm.h"
15 #include "map.h"
16 #include "dir.h"
17 #include "user.h"
18 #include "kernel.h"
19 #include "proc.h"
20 #include "buf.h"
21 #include "inode.h"
22 #include "seg.h"
23 #include "acct.h"
24 #include "wait.h"
25 #include "vm.h"
26 #include "text.h"
27 #include "file.h"
28 #include "quota.h"
29 #include "uio.h"
30 #include "mbuf.h"
31 
32 /*
33  * Clear any pending stops for top and all descendents.
34  */
35 spgrp(top)
36 	struct proc *top;
37 {
38 	register struct proc *p;
39 	int f = 0;
40 
41 	p = top;
42 	for (;;) {
43 		p->p_sig &=
44 			  ~(sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU));
45 		f++;
46 		/*
47 		 * If this process has children, descend to them next,
48 		 * otherwise do any siblings, and if done with this level,
49 		 * follow back up the tree (but not past top).
50 		 */
51 		if (p->p_cptr)
52 			p = p->p_cptr;
53 		else if (p == top)
54 			return (f);
55 		else if (p->p_osptr)
56 			p = p->p_osptr;
57 		else for (;;) {
58 			p = p->p_pptr;
59 			if (p == top)
60 				return (f);
61 			if (p->p_osptr) {
62 				p = p->p_osptr;
63 				break;
64 			}
65 		}
66 	}
67 }
68 
69 /*
70  * Is p an inferior of the current process?
71  */
72 inferior(p)
73 	register struct proc *p;
74 {
75 
76 	for (; p != u.u_procp; p = p->p_pptr)
77 		if (p->p_ppid == 0)
78 			return (0);
79 	return (1);
80 }
81 
82 struct proc *
83 pfind(pid)
84 	int pid;
85 {
86 	register struct proc *p;
87 
88 	for (p = &proc[pidhash[PIDHASH(pid)]]; p != &proc[0]; p = &proc[p->p_idhash])
89 		if (p->p_pid == pid)
90 			return (p);
91 	return ((struct proc *)0);
92 }
93 
94 /*
95  * init the process queues
96  */
97 pqinit()
98 {
99 	register struct proc *p;
100 
101 	/*
102 	 * most procs are initially on freequeue
103 	 *	nb: we place them there in their "natural" order.
104 	 */
105 
106 	freeproc = NULL;
107 	for (p = procNPROC; --p > proc; freeproc = p)
108 		p->p_nxt = freeproc;
109 
110 	/*
111 	 * but proc[0] is special ...
112 	 */
113 
114 	allproc = p;
115 	p->p_nxt = NULL;
116 	p->p_prev = &allproc;
117 
118 	zombproc = NULL;
119 }
120