aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/procstat/procstat_bin.c
diff options
context:
space:
mode:
authorStanislav Sedov <stas@FreeBSD.org>2011-05-12 10:11:39 +0000
committerStanislav Sedov <stas@FreeBSD.org>2011-05-12 10:11:39 +0000
commit0daf62d9f5f7d2c15d00d71eb519b90516df016f (patch)
tree9f873599b157e2ba06c3088d82cad8a221b42d18 /usr.bin/procstat/procstat_bin.c
parent4b5404a9dec82a247f7298f40f2df475833f8e50 (diff)
downloadsrc-0daf62d9f5f7d2c15d00d71eb519b90516df016f.tar.gz
src-0daf62d9f5f7d2c15d00d71eb519b90516df016f.zip
- Commit work from libprocstat project. These patches add support for runtime
file and processes information retrieval from the running kernel via sysctl in the form of new library, libprocstat. The library also supports KVM backend for analyzing memory crash dumps. Both procstat(1) and fstat(1) utilities have been modified to take advantage of the library (as the bonus point the fstat(1) utility no longer need superuser privileges to operate), and the procstat(1) utility is now able to display information from memory dumps as well. The newly introduced fuser(1) utility also uses this library and able to operate via sysctl and kvm backends. The library is by no means complete (e.g. KVM backend is missing vnode name resolution routines, and there're no manpages for the library itself) so I plan to improve it further. I'm commiting it so it will get wider exposure and review. We won't be able to MFC this work as it relies on changes in HEAD, which was introduced some time ago, that break kernel ABI. OTOH we may be able to merge the library with KVM backend if we really need it there. Discussed with: rwatson
Notes
Notes: svn path=/head/; revision=221807
Diffstat (limited to 'usr.bin/procstat/procstat_bin.c')
-rw-r--r--usr.bin/procstat/procstat_bin.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.bin/procstat/procstat_bin.c b/usr.bin/procstat/procstat_bin.c
index 8ed5efed9a1a..cf4ca5b4644c 100644
--- a/usr.bin/procstat/procstat_bin.c
+++ b/usr.bin/procstat/procstat_bin.c
@@ -32,6 +32,7 @@
#include <err.h>
#include <errno.h>
+#include <libprocstat.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
@@ -39,7 +40,7 @@
#include "procstat.h"
void
-procstat_bin(pid_t pid, struct kinfo_proc *kipp)
+procstat_bin(struct kinfo_proc *kipp)
{
char pathname[PATH_MAX];
int error, name[4];
@@ -51,12 +52,12 @@ procstat_bin(pid_t pid, struct kinfo_proc *kipp)
name[0] = CTL_KERN;
name[1] = KERN_PROC;
name[2] = KERN_PROC_PATHNAME;
- name[3] = pid;
+ name[3] = kipp->ki_pid;
len = sizeof(pathname);
error = sysctl(name, 4, pathname, &len, NULL, 0);
if (error < 0 && errno != ESRCH) {
- warn("sysctl: kern.proc.pathname: %d", pid);
+ warn("sysctl: kern.proc.pathname: %d", kipp->ki_pid);
return;
}
if (error < 0)
@@ -64,7 +65,7 @@ procstat_bin(pid_t pid, struct kinfo_proc *kipp)
if (len == 0 || strlen(pathname) == 0)
strcpy(pathname, "-");
- printf("%5d ", pid);
+ printf("%5d ", kipp->ki_pid);
printf("%-16s ", kipp->ki_comm);
printf("%s\n", pathname);
}