xref: /original-bsd/sys/kern/kern_proc.c (revision a0a7d8f4)
1 /*	kern_proc.c	6.5	84/12/20	*/
2 
3 #include "../machine/reg.h"
4 #include "../machine/pte.h"
5 #include "../machine/psl.h"
6 
7 #include "param.h"
8 #include "systm.h"
9 #include "map.h"
10 #include "dir.h"
11 #include "user.h"
12 #include "kernel.h"
13 #include "proc.h"
14 #include "buf.h"
15 #include "inode.h"
16 #include "seg.h"
17 #include "acct.h"
18 #include "wait.h"
19 #include "vm.h"
20 #include "text.h"
21 #include "file.h"
22 #include "quota.h"
23 #include "uio.h"
24 #include "mbuf.h"
25 
26 /*
27  * Change the process group of top and all descendents to npgrp.
28  * If npgrp is -1, instead clear any pending stops.
29  */
30 spgrp(top, npgrp)
31 	struct proc *top;
32 {
33 	register struct proc *p;
34 	int f = 0;
35 
36 	p = top;
37 	for (;;) {
38 		if (npgrp == -1)
39 			p->p_sig &=
40 			  ~(sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU));
41 		else
42 			p->p_pgrp = npgrp;
43 		f++;
44 		/*
45 		 * If this process has children, descend to them next,
46 		 * otherwise do any siblings, and if done with this level,
47 		 * follow back up the tree (but not past top).
48 		 */
49 		if (p->p_cptr)
50 			p = p->p_cptr;
51 		else if (p == top)
52 			return (f);
53 		else if (p->p_osptr)
54 			p = p->p_osptr;
55 		else for (;;) {
56 			p = p->p_pptr;
57 			if (p == top)
58 				return (f);
59 if (p == &proc[1])
60 	panic("spgrp");
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