summaryrefslogtreecommitdiff
path: root/usr.bin/top/utils.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-10-07 06:26:13 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-10-07 06:26:13 +0000
commit2bccf344d8a3f9f34752e51ac50df53503c76f94 (patch)
tree0a07b2d089a5058b9680ac02f8bc303ab79cd6d9 /usr.bin/top/utils.c
parent21dda97f12ab9e6f16723ca5550c186a3b677b32 (diff)
introduce -p option and p command to only show a single process.
From Patrick Latifi. ok deraadt@ millert@
Diffstat (limited to 'usr.bin/top/utils.c')
-rw-r--r--usr.bin/top/utils.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/usr.bin/top/utils.c b/usr.bin/top/utils.c
index 7a6ec4f2e28..adae8630f56 100644
--- a/usr.bin/top/utils.c
+++ b/usr.bin/top/utils.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utils.c,v 1.13 2003/07/07 21:36:52 deraadt Exp $ */
+/* $OpenBSD: utils.c,v 1.14 2004/10/07 06:26:12 otto Exp $ */
/*
* Top users/processes display for Unix
@@ -32,13 +32,15 @@
* This file contains various handy utilities used by top.
*/
-#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "top.h"
+#include "machine.h"
#include "utils.h"
int
@@ -328,3 +330,18 @@ format_k(int amt)
snprintf(ret, sizeof(retarray[0]), "%d%c", amt, tag);
return (ret);
}
+
+int
+find_pid(pid_t pid)
+{
+ struct kinfo_proc2 *pbase, *cur;
+ int i, nproc;
+
+ if ((pbase = getprocs(KERN_PROC_KTHREAD, 0, &nproc)) == NULL)
+ quit(23);
+
+ for (i = 0, cur = pbase; i < nproc; i++, cur++)
+ if (cur->p_pid == pid)
+ return 1;
+ return 0;
+}