summaryrefslogtreecommitdiff
path: root/usr.bin/top
diff options
context:
space:
mode:
authorAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-06-03 06:46:48 +0000
committerAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-06-03 06:46:48 +0000
commit51d300672358aa44ce92a29fd1d1377399f04979 (patch)
treee8358567e288753a566c4fa3e405d27015fd9e01 /usr.bin/top
parent77392538f354d25a630e54329f54ec05be2159a1 (diff)
Use KERN_NPROCS to get the number of processes on the system, to
determine the amount of space we'll need to store the information. The alternative, calling sysctl() with a NULL argument for data, meant the kernel had to go through the process table.
Diffstat (limited to 'usr.bin/top')
-rw-r--r--usr.bin/top/machine.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index a10f505bef8..a15ec570f29 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.23 2001/02/22 03:10:24 deraadt Exp $ */
+/* $OpenBSD: machine.c,v 1.24 2001/06/03 06:46:47 angelos Exp $ */
/*
* top - a top users display for Unix
@@ -274,18 +274,20 @@ getprocs(op, arg, cnt)
int op, arg;
int *cnt;
{
- size_t size = 0;
+ size_t size = sizeof(int);
int mib[4] = {CTL_KERN, KERN_PROC, op, arg};
- int st, nprocs;
+ int smib[2] = {CTL_KERN, KERN_NPROCS};
static struct kinfo_proc *procbase;
+ int st;
- st = sysctl(mib, 4, NULL, &size, NULL, 0);
+ st = sysctl(smib, 2, cnt, &size, NULL, 0);
if (st == -1) {
/* _kvm_syserr(kd, kd->program, "kvm_getprocs"); */
return (0);
}
if (procbase)
free(procbase);
+ size = (6 * (*cnt) * sizeof(struct kinfo_proc)) / 5;
procbase = (struct kinfo_proc *)malloc(size);
if (procbase == NULL)
return (0);
@@ -300,7 +302,6 @@ getprocs(op, arg, cnt)
size, sizeof(struct kinfo_proc)); */
return (0);
}
- *cnt = size / sizeof(struct kinfo_proc);
return (procbase);
}