Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
0880b18e | 2 | * Copyright (c) 1982, 1986 Regents of the University of California. |
da7c5cc6 KM |
3 | * All rights reserved. The Berkeley software License Agreement |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
db5db04d | 6 | * @(#)kern_proc.c 7.2 (Berkeley) %G% |
da7c5cc6 | 7 | */ |
961945a8 SL |
8 | |
9 | #include "../machine/reg.h" | |
10 | #include "../machine/pte.h" | |
11 | #include "../machine/psl.h" | |
29dd101b | 12 | |
94368568 JB |
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" | |
94368568 JB |
21 | #include "seg.h" |
22 | #include "acct.h" | |
23 | #include "wait.h" | |
24 | #include "vm.h" | |
25 | #include "text.h" | |
26 | #include "file.h" | |
27 | #include "quota.h" | |
28 | #include "uio.h" | |
29 | #include "mbuf.h" | |
a1bce776 | 30 | |
bdf8c113 | 31 | /* |
f6ab5a0c | 32 | * Clear any pending stops for top and all descendents. |
bdf8c113 | 33 | */ |
f6ab5a0c | 34 | spgrp(top) |
bdf8c113 | 35 | struct proc *top; |
4147b3f6 | 36 | { |
bdf8c113 | 37 | register struct proc *p; |
4147b3f6 BJ |
38 | int f = 0; |
39 | ||
bdf8c113 MK |
40 | p = top; |
41 | for (;;) { | |
f6ab5a0c | 42 | p->p_sig &= |
bdf8c113 | 43 | ~(sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU)); |
4147b3f6 BJ |
44 | f++; |
45 | /* | |
bdf8c113 MK |
46 | * If this process has children, descend to them next, |
47 | * otherwise do any siblings, and if done with this level, | |
48 | * follow back up the tree (but not past top). | |
4147b3f6 | 49 | */ |
bdf8c113 MK |
50 | if (p->p_cptr) |
51 | p = p->p_cptr; | |
52 | else if (p == top) | |
53 | return (f); | |
54 | else if (p->p_osptr) | |
55 | p = p->p_osptr; | |
56 | else for (;;) { | |
57 | p = p->p_pptr; | |
58 | if (p == top) | |
59 | return (f); | |
bdf8c113 MK |
60 | if (p->p_osptr) { |
61 | p = p->p_osptr; | |
62 | break; | |
63 | } | |
64 | } | |
4147b3f6 | 65 | } |
4147b3f6 BJ |
66 | } |
67 | ||
29dd101b | 68 | /* |
4147b3f6 | 69 | * Is p an inferior of the current process? |
29dd101b | 70 | */ |
4147b3f6 | 71 | inferior(p) |
a2a2a0d6 | 72 | register struct proc *p; |
29dd101b | 73 | { |
29dd101b | 74 | |
4147b3f6 BJ |
75 | for (; p != u.u_procp; p = p->p_pptr) |
76 | if (p->p_ppid == 0) | |
77 | return (0); | |
78 | return (1); | |
29dd101b | 79 | } |
a2a2a0d6 BJ |
80 | |
81 | struct proc * | |
82 | pfind(pid) | |
83 | int pid; | |
84 | { | |
85 | register struct proc *p; | |
86 | ||
87 | for (p = &proc[pidhash[PIDHASH(pid)]]; p != &proc[0]; p = &proc[p->p_idhash]) | |
88 | if (p->p_pid == pid) | |
89 | return (p); | |
90 | return ((struct proc *)0); | |
91 | } | |
1d348849 MK |
92 | |
93 | /* | |
94 | * init the process queues | |
95 | */ | |
96 | pqinit() | |
97 | { | |
98 | register struct proc *p; | |
99 | ||
100 | /* | |
101 | * most procs are initially on freequeue | |
102 | * nb: we place them there in their "natural" order. | |
103 | */ | |
104 | ||
105 | freeproc = NULL; | |
106 | for (p = procNPROC; --p > proc; freeproc = p) | |
107 | p->p_nxt = freeproc; | |
108 | ||
109 | /* | |
110 | * but proc[0] is special ... | |
111 | */ | |
112 | ||
113 | allproc = p; | |
114 | p->p_nxt = NULL; | |
115 | p->p_prev = &allproc; | |
116 | ||
117 | zombproc = NULL; | |
118 | } |