Add support for the POSIX.2 "etime" keyword - shows the elapsed time
since the process was started. Fix a couple of style nits as well. Fix for part of PR standards/11224.
This commit is contained in:
parent
a6b219ed94
commit
63e11689ca
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.26 2004/03/27 12:09:28 simonb Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.27 2004/03/27 14:49:13 simonb Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
@ -52,6 +52,7 @@ int donlist(void);
|
||||
int donlist_sysctl(void);
|
||||
void fmt_puts(char *, int *);
|
||||
void fmt_putc(int, int *);
|
||||
void elapsed(void *, VARENT *, int);
|
||||
double getpcpu(struct kinfo_proc2 *);
|
||||
double getpmem(struct kinfo_proc2 *);
|
||||
void gname(void *, VARENT *, int);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: keyword.c,v 1.38 2004/03/27 12:44:08 simonb Exp $ */
|
||||
/* $NetBSD: keyword.c,v 1.39 2004/03/27 14:49:13 simonb Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: keyword.c,v 1.38 2004/03/27 12:44:08 simonb Exp $");
|
||||
__RCSID("$NetBSD: keyword.c,v 1.39 2004/03/27 14:49:13 simonb Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -104,6 +104,7 @@ VAR var[] = {
|
||||
{"ctime", "CTIME", 0, putimeval, POFF(p_uctime_sec), TIMEVAL},
|
||||
GID("egid", "EGID", p_gid),
|
||||
{"egroup", "EGROUP", LJUST, gname},
|
||||
{"etime", "ELAPSED", 0, elapsed, POFF(p_ustart_sec), TIMEVAL},
|
||||
UID("euid", "EUID", p_uid),
|
||||
{"euser", "EUSER", LJUST, uname},
|
||||
PVAR("f", "F", 0, p_flag, INT, "x"),
|
||||
|
106
bin/ps/print.c
106
bin/ps/print.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: print.c,v 1.86 2004/03/27 14:09:10 simonb Exp $ */
|
||||
/* $NetBSD: print.c,v 1.87 2004/03/27 14:49:13 simonb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
@ -70,7 +70,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: print.c,v 1.86 2004/03/27 14:09:10 simonb Exp $");
|
||||
__RCSID("$NetBSD: print.c,v 1.87 2004/03/27 14:49:13 simonb Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -107,6 +107,8 @@ static void doubleprintorsetwidth(VAR *, double, int, int);
|
||||
static void intprintorsetwidth(VAR *, int, int);
|
||||
static void strprintorsetwidth(VAR *, const char *, int);
|
||||
|
||||
static time_t now;
|
||||
|
||||
#define min(a,b) ((a) <= (b) ? (a) : (b))
|
||||
|
||||
static int
|
||||
@ -758,7 +760,6 @@ started(void *arg, VARENT *ve, int mode)
|
||||
{
|
||||
struct kinfo_proc2 *k;
|
||||
VAR *v;
|
||||
static time_t now;
|
||||
time_t startt;
|
||||
struct tm *tp;
|
||||
char buf[100], *cp;
|
||||
@ -773,7 +774,7 @@ started(void *arg, VARENT *ve, int mode)
|
||||
|
||||
startt = k->p_ustart_sec;
|
||||
tp = localtime(&startt);
|
||||
if (!now)
|
||||
if (now == 0)
|
||||
(void)time(&now);
|
||||
if (now - k->p_ustart_sec < SECSPERDAY)
|
||||
/* I *hate* SCCS... */
|
||||
@ -819,6 +820,99 @@ lstarted(void *arg, VARENT *ve, int mode)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
elapsed(void *arg, VARENT *ve, int mode)
|
||||
{
|
||||
struct kinfo_proc2 *k;
|
||||
VAR *v;
|
||||
int32_t origseconds, secs, mins, hours, days;
|
||||
int fmtlen, printed_something;
|
||||
|
||||
k = arg;
|
||||
v = ve->var;
|
||||
if (k->p_uvalid == 0) {
|
||||
origseconds = 0;
|
||||
} else {
|
||||
if (now == 0)
|
||||
(void)time(&now);
|
||||
origseconds = now - k->p_ustart_sec;
|
||||
if (origseconds < 0) {
|
||||
/*
|
||||
* Don't try to be fancy if the machine's
|
||||
* clock has been rewound to before the
|
||||
* process "started".
|
||||
*/
|
||||
origseconds = 0;
|
||||
}
|
||||
}
|
||||
|
||||
secs = origseconds;
|
||||
mins = secs / SECSPERMIN;
|
||||
secs %= SECSPERMIN;
|
||||
hours = mins / MINSPERHOUR;
|
||||
mins %= MINSPERHOUR;
|
||||
days = hours / HOURSPERDAY;
|
||||
hours %= HOURSPERDAY;
|
||||
|
||||
if (mode == WIDTHMODE) {
|
||||
if (origseconds == 0)
|
||||
/* non-zero so fmtlen is calculated at least once */
|
||||
origseconds = 1;
|
||||
|
||||
if (origseconds > v->longestp) {
|
||||
v->longestp = origseconds;
|
||||
|
||||
if (days > 0) {
|
||||
/* +9 for "-hh:mm:ss" */
|
||||
fmtlen = iwidth(days) + 9;
|
||||
} else if (hours > 0) {
|
||||
/* +6 for "mm:ss" */
|
||||
fmtlen = iwidth(hours) + 6;
|
||||
} else {
|
||||
/* +3 for ":ss" */
|
||||
fmtlen = iwidth(mins) + 3;
|
||||
}
|
||||
|
||||
if (fmtlen > v->width)
|
||||
v->width = fmtlen;
|
||||
}
|
||||
} else {
|
||||
fmtlen = v->width;
|
||||
|
||||
if (days > 0) {
|
||||
(void)printf("%*d", fmtlen - 9, days);
|
||||
printed_something = 1;
|
||||
} else if (fmtlen > 9) {
|
||||
(void)printf("%*s", fmtlen - 9, "");
|
||||
}
|
||||
if (fmtlen > 9)
|
||||
fmtlen = 9;
|
||||
|
||||
if (printed_something) {
|
||||
(void)printf("-%.*d", fmtlen - 7, hours);
|
||||
printed_something = 1;
|
||||
} else if (hours > 0) {
|
||||
(void)printf("%*d", fmtlen - 6, hours);
|
||||
printed_something = 1;
|
||||
} else if (fmtlen > 6) {
|
||||
(void)printf("%*s", fmtlen - 6, "");
|
||||
}
|
||||
if (fmtlen > 6)
|
||||
fmtlen = 6;
|
||||
|
||||
/* Don't need to set fmtlen or printed_something any more... */
|
||||
if (printed_something) {
|
||||
(void)printf(":%.*d", fmtlen - 4, mins);
|
||||
} else if (mins > 0) {
|
||||
(void)printf("%*d", fmtlen - 3, mins);
|
||||
} else if (fmtlen > 3) {
|
||||
(void)printf("%*s", fmtlen - 3, "0");
|
||||
}
|
||||
|
||||
(void)printf(":%.2d", secs);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wchan(void *arg, VARENT *ve, int mode)
|
||||
{
|
||||
@ -1273,8 +1367,8 @@ putimeval(void *arg, VARENT *ve, int mode)
|
||||
}
|
||||
|
||||
if (mode == WIDTHMODE) {
|
||||
if (!secs)
|
||||
/* zero doesn't give correct width... */
|
||||
if (secs == 0)
|
||||
/* non-zero so fmtlen is calculated at least once */
|
||||
secs = 1;
|
||||
if (secs > v->longestu) {
|
||||
v->longestu = secs;
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: ps.1,v 1.65 2004/02/13 09:55:24 wiz Exp $
|
||||
.\" $NetBSD: ps.1,v 1.66 2004/03/27 14:49:13 simonb Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -29,7 +29,7 @@
|
||||
.\"
|
||||
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
|
||||
.\"
|
||||
.Dd March 1, 2003
|
||||
.Dd March 27, 2004
|
||||
.Dt PS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -467,6 +467,9 @@ accumulated CPU time of all children that have exited
|
||||
effective group id
|
||||
.It egroup
|
||||
group name (from egid)
|
||||
.It etime
|
||||
elapsed time since the process was started, in the form
|
||||
.Li [[dd-]hh:]mm:ss
|
||||
.It euid
|
||||
effective user id
|
||||
.It euser
|
||||
|
Loading…
x
Reference in New Issue
Block a user