diff options
author | marcus <marcus@FreeBSD.org> | 2008-02-09 05:16:26 +0000 |
---|---|---|
committer | marcus <marcus@FreeBSD.org> | 2008-02-09 05:16:26 +0000 |
commit | 7e24637c24d89a152b59a841be37492eb89f6306 (patch) | |
tree | 20e45e9043b089cddbc2ac777d162e09cb3e0524 /usr.bin/procstat/procstat_files.c | |
parent | 7445f79ec2116bd87b6972c03986e41535d73509 (diff) | |
download | FreeBSD-src-7e24637c24d89a152b59a841be37492eb89f6306.zip FreeBSD-src-7e24637c24d89a152b59a841be37492eb89f6306.tar.gz |
Add support for displaying a process' current working directory, root
directory, and jail directory within procstat. While this functionality
is available already in fstat, encapsulating it in the kern.proc.filedesc
sysctl makes it accessible without using kvm and thus without needing
elevated permissions.
The new procstat output looks like:
PID COMM FD T V FLAGS REF OFFSET PRO NAME
76792 tcsh cwd v d -------- - - - /usr/src
76792 tcsh root v d -------- - - - /
76792 tcsh 15 v c rw------ 16 9130 - -
76792 tcsh 16 v c rw------ 16 9130 - -
76792 tcsh 17 v c rw------ 16 9130 - -
76792 tcsh 18 v c rw------ 16 9130 - -
76792 tcsh 19 v c rw------ 16 9130 - -
I am also bumping __FreeBSD_version for this as this new feature will be
used in at least one port.
Reviewed by: rwatson
Approved by: rwatson
Diffstat (limited to 'usr.bin/procstat/procstat_files.c')
-rw-r--r-- | usr.bin/procstat/procstat_files.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/usr.bin/procstat/procstat_files.c b/usr.bin/procstat/procstat_files.c index 98e4ef6..950b70d 100644 --- a/usr.bin/procstat/procstat_files.c +++ b/usr.bin/procstat/procstat_files.c @@ -140,7 +140,7 @@ procstat_files(pid_t pid, struct kinfo_proc *kipp) size_t len; if (!hflag) - printf("%5s %-16s %3s %1s %1s %-8s %3s %7s %-3s %-12s\n", + printf("%5s %-16s %4s %1s %1s %-8s %3s %7s %-3s %-12s\n", "PID", "COMM", "FD", "T", "V", "FLAGS", "REF", "OFFSET", "PRO", "NAME"); @@ -172,7 +172,23 @@ procstat_files(pid_t pid, struct kinfo_proc *kipp) errx(-1, "kinfo_file mismatch"); printf("%5d ", pid); printf("%-16s ", kipp->ki_comm); - printf("%3d ", kif->kf_fd); + switch (kif->kf_fd) { + case KF_FD_TYPE_CWD: + printf(" cwd "); + break; + + case KF_FD_TYPE_ROOT: + printf("root "); + break; + + case KF_FD_TYPE_JAIL: + printf("jail "); + break; + + default: + printf("%4d ", kif->kf_fd); + break; + } switch (kif->kf_type) { case KF_TYPE_VNODE: str = "v"; @@ -264,8 +280,14 @@ procstat_files(pid_t pid, struct kinfo_proc *kipp) printf("%s", kif->kf_flags & KF_FLAG_NONBLOCK ? "n" : "-"); printf("%s", kif->kf_flags & KF_FLAG_DIRECT ? "d" : "-"); printf("%s ", kif->kf_flags & KF_FLAG_HASLOCK ? "l" : "-"); - printf("%3d ", kif->kf_ref_count); - printf("%7jd ", (intmax_t)kif->kf_offset); + if (kif->kf_ref_count > -1) + printf("%3d ", kif->kf_ref_count); + else + printf("%3c ", '-'); + if (kif->kf_offset > -1) + printf("%7jd ", (intmax_t)kif->kf_offset); + else + printf("%7c ", '-'); switch (kif->kf_type) { case KF_TYPE_VNODE: |