summaryrefslogtreecommitdiffstats
path: root/bin/ps/print.c
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2011-03-24 20:15:42 +0000
committertrasz <trasz@FreeBSD.org>2011-03-24 20:15:42 +0000
commite94d4d2ed6a442604885618a239373e8df23c269 (patch)
treef3ca70d60b078cb78e13a6e354b1cb5cc99b0ca6 /bin/ps/print.c
parentba27262ba1ab13c1e02f35018f43d97e2cf8e422 (diff)
downloadFreeBSD-src-e94d4d2ed6a442604885618a239373e8df23c269.zip
FreeBSD-src-e94d4d2ed6a442604885618a239373e8df23c269.tar.gz
Add proper width calculation for time fields (time, cputime and usertime).
This fixes the ugly overflow in "ps aux" output for "[idle]".
Diffstat (limited to 'bin/ps/print.c')
-rw-r--r--bin/ps/print.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 0c97030..432cffa 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -570,11 +570,20 @@ printtime(KINFO *k, VARENT *ve, long secs, long psecs)
secs += psecs / 100;
psecs = psecs % 100;
}
- (void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld%c%02ld",
+ (void)snprintf(obuff, sizeof(obuff), "%ld:%02ld%c%02ld",
secs / 60, secs % 60, decimal_point, psecs);
(void)printf("%*s", v->width, obuff);
}
+static int
+sizetime(long secs)
+{
+
+ if (secs < 60)
+ return (7);
+ return (log10(secs / 60) + 7);
+}
+
void
cputime(KINFO *k, VARENT *ve)
{
@@ -930,6 +939,17 @@ s_comm(KINFO *k)
}
int
+s_cputime(KINFO *k)
+{
+ long secs;
+
+ secs = k->ki_p->ki_runtime / 1000000;
+ if (sumrusage)
+ secs += k->ki_p->ki_childtime.tv_sec;
+ return (sizetime(secs));
+}
+
+int
s_label(KINFO *k)
{
char *string = NULL;
@@ -975,3 +995,25 @@ s_logname(KINFO *k)
return (strlen(s));
}
+
+int
+s_systime(KINFO *k)
+{
+ long secs;
+
+ secs = k->ki_p->ki_rusage.ru_stime.tv_sec;
+ if (sumrusage)
+ secs += k->ki_p->ki_childstime.tv_sec;
+ return (sizetime(secs));
+}
+
+int
+s_usertime(KINFO *k)
+{
+ long secs;
+
+ secs = k->ki_p->ki_rusage.ru_utime.tv_sec;
+ if (sumrusage)
+ secs += k->ki_p->ki_childutime.tv_sec;
+ return (sizetime(secs));
+}
OpenPOWER on IntegriCloud