Commit | Line | Data |
---|---|---|
da7c5cc6 KM |
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.6 (Berkeley) %G% | |
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" | |
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" | |
a1bce776 | 31 | |
bdf8c113 MK |
32 | /* |
33 | * Change the process group of top and all descendents to npgrp. | |
34 | * If npgrp is -1, instead clear any pending stops. | |
35 | */ | |
4147b3f6 | 36 | spgrp(top, npgrp) |
bdf8c113 | 37 | struct proc *top; |
4147b3f6 | 38 | { |
bdf8c113 | 39 | register struct proc *p; |
4147b3f6 BJ |
40 | int f = 0; |
41 | ||
bdf8c113 MK |
42 | p = top; |
43 | for (;;) { | |
44 | if (npgrp == -1) | |
45 | p->p_sig &= | |
46 | ~(sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU)); | |
47 | else | |
4147b3f6 BJ |
48 | p->p_pgrp = npgrp; |
49 | f++; | |
50 | /* | |
bdf8c113 MK |
51 | * If this process has children, descend to them next, |
52 | * otherwise do any siblings, and if done with this level, | |
53 | * follow back up the tree (but not past top). | |
4147b3f6 | 54 | */ |
bdf8c113 MK |
55 | if (p->p_cptr) |
56 | p = p->p_cptr; | |
57 | else if (p == top) | |
58 | return (f); | |
59 | else if (p->p_osptr) | |
60 | p = p->p_osptr; | |
61 | else for (;;) { | |
62 | p = p->p_pptr; | |
63 | if (p == top) | |
64 | return (f); | |
65 | if (p == &proc[1]) | |
66 | panic("spgrp"); | |
67 | if (p->p_osptr) { | |
68 | p = p->p_osptr; | |
69 | break; | |
70 | } | |
71 | } | |
4147b3f6 | 72 | } |
4147b3f6 BJ |
73 | } |
74 | ||
29dd101b | 75 | /* |
4147b3f6 | 76 | * Is p an inferior of the current process? |
29dd101b | 77 | */ |
4147b3f6 | 78 | inferior(p) |
a2a2a0d6 | 79 | register struct proc *p; |
29dd101b | 80 | { |
29dd101b | 81 | |
4147b3f6 BJ |
82 | for (; p != u.u_procp; p = p->p_pptr) |
83 | if (p->p_ppid == 0) | |
84 | return (0); | |
85 | return (1); | |
29dd101b | 86 | } |
a2a2a0d6 BJ |
87 | |
88 | struct proc * | |
89 | pfind(pid) | |
90 | int pid; | |
91 | { | |
92 | register struct proc *p; | |
93 | ||
94 | for (p = &proc[pidhash[PIDHASH(pid)]]; p != &proc[0]; p = &proc[p->p_idhash]) | |
95 | if (p->p_pid == pid) | |
96 | return (p); | |
97 | return ((struct proc *)0); | |
98 | } | |
1d348849 MK |
99 | |
100 | /* | |
101 | * init the process queues | |
102 | */ | |
103 | pqinit() | |
104 | { | |
105 | register struct proc *p; | |
106 | ||
107 | /* | |
108 | * most procs are initially on freequeue | |
109 | * nb: we place them there in their "natural" order. | |
110 | */ | |
111 | ||
112 | freeproc = NULL; | |
113 | for (p = procNPROC; --p > proc; freeproc = p) | |
114 | p->p_nxt = freeproc; | |
115 | ||
116 | /* | |
117 | * but proc[0] is special ... | |
118 | */ | |
119 | ||
120 | allproc = p; | |
121 | p->p_nxt = NULL; | |
122 | p->p_prev = &allproc; | |
123 | ||
124 | zombproc = NULL; | |
125 | } |