cleanups from Sam: format, spl's, ptrace defs
[unix-history] / usr / src / sys / kern / kern_proc.c
CommitLineData
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 *
f6ab5a0c 6 * @(#)kern_proc.c 6.7 (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"
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 32/*
f6ab5a0c 33 * Clear any pending stops for top and all descendents.
bdf8c113 34 */
f6ab5a0c 35spgrp(top)
bdf8c113 36 struct proc *top;
4147b3f6 37{
bdf8c113 38 register struct proc *p;
4147b3f6
BJ
39 int f = 0;
40
bdf8c113
MK
41 p = top;
42 for (;;) {
f6ab5a0c 43 p->p_sig &=
bdf8c113 44 ~(sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU));
4147b3f6
BJ
45 f++;
46 /*
bdf8c113
MK
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).
4147b3f6 50 */
bdf8c113
MK
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);
bdf8c113
MK
61 if (p->p_osptr) {
62 p = p->p_osptr;
63 break;
64 }
65 }
4147b3f6 66 }
4147b3f6
BJ
67}
68
29dd101b 69/*
4147b3f6 70 * Is p an inferior of the current process?
29dd101b 71 */
4147b3f6 72inferior(p)
a2a2a0d6 73 register struct proc *p;
29dd101b 74{
29dd101b 75
4147b3f6
BJ
76 for (; p != u.u_procp; p = p->p_pptr)
77 if (p->p_ppid == 0)
78 return (0);
79 return (1);
29dd101b 80}
a2a2a0d6
BJ
81
82struct proc *
83pfind(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}
1d348849
MK
93
94/*
95 * init the process queues
96 */
97pqinit()
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}