From 0daf62d9f5f7d2c15d00d71eb519b90516df016f Mon Sep 17 00:00:00 2001 From: Stanislav Sedov Date: Thu, 12 May 2011 10:11:39 +0000 Subject: - 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 --- usr.bin/procstat/procstat_bin.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'usr.bin/procstat/procstat_bin.c') diff --git a/usr.bin/procstat/procstat_bin.c b/usr.bin/procstat/procstat_bin.c index 8ed5efed9a1a9..cf4ca5b4644c9 100644 --- a/usr.bin/procstat/procstat_bin.c +++ b/usr.bin/procstat/procstat_bin.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -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); } -- cgit v1.2.3