svn commit: r230918 - stable/9/usr.bin/procstat
Mikolaj Golub
trociny at FreeBSD.org
Thu Feb 2 18:22:26 UTC 2012
Author: trociny
Date: Thu Feb 2 18:22:25 2012
New Revision: 230918
URL: http://svn.freebsd.org/changeset/base/230918
Log:
MFC r227956, r228090, r228446, r230471, r230548:
r227956:
Add -l flag to display resource limits.
PR: bin/161257
Reviewed by: kib
r228090:
Update SYNOPSIS to include the flags added recently.
Spotted by: jhb
r228446:
Make procstat -l output similar to the output of limits(1).
Suggested by: jhb
r230471, r230548:
Make procstat -l to work with the new version of kern.proc.rlimit.
Submitted by: Andrey Zonov <andrey at zonov.org>
Added:
stable/9/usr.bin/procstat/procstat_rlimit.c
- copied, changed from r227956, head/usr.bin/procstat/procstat_rlimit.c
Modified:
stable/9/usr.bin/procstat/Makefile
stable/9/usr.bin/procstat/procstat.1
stable/9/usr.bin/procstat/procstat.c
stable/9/usr.bin/procstat/procstat.h
Directory Properties:
stable/9/usr.bin/procstat/ (props changed)
Modified: stable/9/usr.bin/procstat/Makefile
==============================================================================
--- stable/9/usr.bin/procstat/Makefile Thu Feb 2 18:17:49 2012 (r230917)
+++ stable/9/usr.bin/procstat/Makefile Thu Feb 2 18:22:25 2012 (r230918)
@@ -10,6 +10,7 @@ SRCS= procstat.c \
procstat_cred.c \
procstat_files.c \
procstat_kstack.c \
+ procstat_rlimit.c \
procstat_sigs.c \
procstat_threads.c \
procstat_vm.c
Modified: stable/9/usr.bin/procstat/procstat.1
==============================================================================
--- stable/9/usr.bin/procstat/procstat.1 Thu Feb 2 18:17:49 2012 (r230917)
+++ stable/9/usr.bin/procstat/procstat.1 Thu Feb 2 18:22:25 2012 (r230918)
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 22, 2011
+.Dd November 28, 2011
.Dt PROCSTAT 1
.Os
.Sh NAME
@@ -37,7 +37,7 @@
.Op Fl n
.Op Fl C
.Op Fl w Ar interval
-.Op Fl b | c | f | i | j | k | s | t | v
+.Op Fl b | c | e | f | i | j | k | l | s | t | v | x
.Op Fl a | Ar pid ...
.Sh DESCRIPTION
The
@@ -69,6 +69,8 @@ Display the stacks of kernel threads in
threads currently running on a CPU and threads with stacks swapped to disk.
If the flag is repeated, function offsets as well as function names are
printed.
+.It Fl l
+Display resource limits for the process.
.It Fl s
Display security credential information for the process.
.It Fl t
Modified: stable/9/usr.bin/procstat/procstat.c
==============================================================================
--- stable/9/usr.bin/procstat/procstat.c Thu Feb 2 18:17:49 2012 (r230917)
+++ stable/9/usr.bin/procstat/procstat.c Thu Feb 2 18:22:25 2012 (r230918)
@@ -39,8 +39,8 @@
#include "procstat.h"
-static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag, sflag, tflag;
-static int vflag, xflag;
+static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag, lflag, sflag;
+static int tflag, vflag, xflag;
int hflag, nflag, Cflag;
static void
@@ -50,7 +50,7 @@ usage(void)
fprintf(stderr, "usage: procstat [-h] [-C] [-M core] [-N system] "
"[-w interval] \n");
fprintf(stderr, " [-b | -c | -e | -f | -i | -j | -k | "
- "-s | -t | -v | -x] [-a | pid ...]\n");
+ "-l | -s | -t | -v | -x] [-a | pid ...]\n");
exit(EX_USAGE);
}
@@ -72,6 +72,8 @@ procstat(struct procstat *prstat, struct
procstat_threads_sigs(prstat, kipp);
else if (kflag)
procstat_kstack(kipp, kflag);
+ else if (lflag)
+ procstat_rlimit(kipp);
else if (sflag)
procstat_cred(kipp);
else if (tflag)
@@ -123,7 +125,7 @@ main(int argc, char *argv[])
interval = 0;
memf = nlistf = NULL;
- while ((ch = getopt(argc, argv, "CN:M:abcefijkhstvw:x")) != -1) {
+ while ((ch = getopt(argc, argv, "CN:M:abcefijklhstvw:x")) != -1) {
switch (ch) {
case 'C':
Cflag++;
@@ -167,6 +169,10 @@ main(int argc, char *argv[])
kflag++;
break;
+ case 'l':
+ lflag++;
+ break;
+
case 'n':
nflag++;
break;
@@ -210,8 +216,8 @@ main(int argc, char *argv[])
argv += optind;
/* We require that either 0 or 1 mode flags be set. */
- tmp = bflag + cflag + eflag + fflag + (kflag ? 1 : 0) + sflag + tflag +
- vflag + xflag;
+ tmp = bflag + cflag + eflag + fflag + (kflag ? 1 : 0) + lflag + sflag +
+ tflag + vflag + xflag;
if (!(tmp == 0 || tmp == 1))
usage();
Modified: stable/9/usr.bin/procstat/procstat.h
==============================================================================
--- stable/9/usr.bin/procstat/procstat.h Thu Feb 2 18:17:49 2012 (r230917)
+++ stable/9/usr.bin/procstat/procstat.h Thu Feb 2 18:22:25 2012 (r230918)
@@ -42,6 +42,7 @@ void procstat_cred(struct kinfo_proc *ki
void procstat_env(struct kinfo_proc *kipp);
void procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_kstack(struct kinfo_proc *kipp, int kflag);
+void procstat_rlimit(struct kinfo_proc *kipp);
void procstat_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_threads(struct kinfo_proc *kipp);
void procstat_threads_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
Copied and modified: stable/9/usr.bin/procstat/procstat_rlimit.c (from r227956, head/usr.bin/procstat/procstat_rlimit.c)
==============================================================================
--- head/usr.bin/procstat/procstat_rlimit.c Thu Nov 24 20:54:06 2011 (r227956, copy source)
+++ stable/9/usr.bin/procstat/procstat_rlimit.c Thu Feb 2 18:22:25 2012 (r230918)
@@ -28,7 +28,6 @@
#include <sys/param.h>
#include <sys/time.h>
-#define _RLIMIT_IDENT
#include <sys/resourcevar.h>
#include <sys/sysctl.h>
#include <sys/user.h>
@@ -36,6 +35,7 @@
#include <err.h>
#include <errno.h>
#include <libprocstat.h>
+#include <libutil.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -43,36 +43,77 @@
#include "procstat.h"
-static struct rlimit rlimit[RLIM_NLIMITS];
+static struct {
+ const char *name;
+ const char *suffix;
+} rlimit_param[13] = {
+ {"cputime", "sec"},
+ {"filesize", "B "},
+ {"datasize", "B "},
+ {"stacksize", "B "},
+ {"coredumpsize", "B "},
+ {"memoryuse", "B "},
+ {"memorylocked", "B "},
+ {"maxprocesses", " "},
+ {"openfiles", " "},
+ {"sbsize", "B "},
+ {"vmemoryuse", "B "},
+ {"pseudo-terminals", " "},
+ {"swapuse", "B "},
+};
+
+#if RLIM_NLIMITS > 13
+#error "Resource limits have grown. Add new entries to rlimit_param[]."
+#endif
+
+static
+const char *humanize_rlimit(int indx, rlim_t limit)
+{
+ static char buf[14];
+ int scale;
+
+ if (limit == RLIM_INFINITY)
+ return ("infinity ");
+
+ scale = humanize_number(buf, sizeof(buf) - 1, (int64_t)limit,
+ rlimit_param[indx].suffix, HN_AUTOSCALE | HN_GETSCALE, HN_DECIMAL);
+ (void)humanize_number(buf, sizeof(buf) - 1, (int64_t)limit,
+ rlimit_param[indx].suffix, HN_AUTOSCALE, HN_DECIMAL);
+ /* Pad with one space if there is no suffix prefix. */
+ if (scale == 0)
+ sprintf(buf + strlen(buf), " ");
+ return (buf);
+}
void
procstat_rlimit(struct kinfo_proc *kipp)
{
- int error, i, name[4];
+ struct rlimit rlimit;
+ int error, i, name[5];
size_t len;
- if (!hflag)
- printf("%5s %-16s %-10s %12s %12s\n", "PID", "COMM", "RLIMIT",
- "CURRENT", "MAX");
+ if (!hflag) {
+ printf("%5s %-16s %-16s %16s %16s\n",
+ "PID", "COMM", "RLIMIT", "SOFT ", "HARD ");
+ }
+ len = sizeof(struct rlimit);
name[0] = CTL_KERN;
name[1] = KERN_PROC;
name[2] = KERN_PROC_RLIMIT;
name[3] = kipp->ki_pid;
- len = sizeof(rlimit);
- error = sysctl(name, 4, rlimit, &len, NULL, 0);
- if (error < 0 && errno != ESRCH) {
- warn("sysctl: kern.proc.rlimit: %d", kipp->ki_pid);
- return;
- }
- if (error < 0 || len != sizeof(rlimit))
- return;
-
for (i = 0; i < RLIM_NLIMITS; i++) {
- printf("%5d %-16s %-10s %12jd %12jd\n", kipp->ki_pid,
- kipp->ki_comm, rlimit_ident[i],
- rlimit[i].rlim_cur == RLIM_INFINITY ?
- -1 : rlimit[i].rlim_cur,
- rlimit[i].rlim_max == RLIM_INFINITY ?
- -1 : rlimit[i].rlim_max);
- }
+ name[4] = i;
+ error = sysctl(name, 5, &rlimit, &len, NULL, 0);
+ if (error < 0 && errno != ESRCH) {
+ warn("sysctl: kern.proc.rlimit: %d", kipp->ki_pid);
+ return;
+ }
+ if (error < 0 || len != sizeof(struct rlimit))
+ return;
+
+ printf("%5d %-16s %-16s ", kipp->ki_pid, kipp->ki_comm,
+ rlimit_param[i].name);
+ printf("%16s ", humanize_rlimit(i, rlimit.rlim_cur));
+ printf("%16s\n", humanize_rlimit(i, rlimit.rlim_max));
+ }
}
More information about the svn-src-stable-9
mailing list