Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/procstat/procstat_bin.c
| Show All 29 Lines | |||||
| #include <sys/param.h> | #include <sys/param.h> | ||||
| #include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
| #include <sys/user.h> | #include <sys/user.h> | ||||
| #include <err.h> | #include <err.h> | ||||
| #include <errno.h> | #include <errno.h> | ||||
| #include <libprocstat.h> | #include <libprocstat.h> | ||||
| #include <limits.h> | #include <limits.h> | ||||
| #include <signal.h> | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "procstat.h" | #include "procstat.h" | ||||
| void | void | ||||
| procstat_bin(struct procstat *prstat, struct kinfo_proc *kipp) | procstat_bin(struct procstat *prstat, struct kinfo_proc *kipp) | ||||
| { | { | ||||
| int osrel; | int osrel; | ||||
| static char pathname[PATH_MAX]; | static char pathname[PATH_MAX]; | ||||
| if ((procstat_opts & PS_OPT_NOHEADER) == 0) | if ((procstat_opts & PS_OPT_NOHEADER) == 0) | ||||
| xo_emit("{T:/%5s %-16s %8s %s}\n", "PID", "COMM", "OSREL", | xo_emit("{T:/%5s %-16s %8s %s}\n", "PID", "COMM", "OSREL", | ||||
| "PATH"); | "PATH"); | ||||
| if (procstat_getpathname(prstat, kipp, pathname, sizeof(pathname)) != 0) | if (kill(kipp->ki_pid, 0) == -1) | ||||
| return; | return; | ||||
| if (strlen(pathname) == 0) | if (procstat_getpathname(prstat, kipp, pathname, sizeof(pathname)) | ||||
| != 0 || strlen(pathname) == 0) | |||||
| strcpy(pathname, "-"); | strcpy(pathname, "-"); | ||||
| if (procstat_getosrel(prstat, kipp, &osrel) != 0) | if (procstat_getosrel(prstat, kipp, &osrel) != 0) | ||||
| return; | osrel = -1; | ||||
| xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid); | xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid); | ||||
| xo_emit("{:command/%-16s/%s} ", kipp->ki_comm); | xo_emit("{:command/%-16s/%s} ", kipp->ki_comm); | ||||
| xo_emit("{:osrel/%8d/%d} ", osrel); | xo_emit("{:osrel/%8d/%d} ", osrel); | ||||
| xo_emit("{:pathname/%s}\n", pathname); | xo_emit("{:pathname/%s}\n", pathname); | ||||
| } | } | ||||