summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2016-09-08 15:11:31 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2016-09-08 15:11:31 +0000
commitb20234ac519101342c49ed6bce4a05e45d0b7e84 (patch)
treedc0b6b480078ecf9e643485ad56258c6abef9364 /bin
parent295ac07191c73fbf7f1e736ed588ad420d343a37 (diff)
etime isn't just an alias for start. the output format is different.
diff from Carlin Bingham. ok millert.
Diffstat (limited to 'bin')
-rw-r--r--bin/ps/extern.h3
-rw-r--r--bin/ps/keyword.c4
-rw-r--r--bin/ps/print.c46
-rw-r--r--bin/ps/ps.18
4 files changed, 53 insertions, 8 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index 64cf9a10da3..802844f8d8d 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.19 2016/01/10 14:04:16 schwarze Exp $ */
+/* $OpenBSD: extern.h,v 1.20 2016/09/08 15:11:29 tedu Exp $ */
/* $NetBSD: extern.h,v 1.10 1995/05/21 13:38:27 mycroft Exp $ */
/*-
@@ -48,6 +48,7 @@ void command(const struct kinfo_proc *, VARENT *);
void cputime(const struct kinfo_proc *, VARENT *);
int donlist(void);
void emulname(const struct kinfo_proc *, VARENT *);
+void elapsed(const struct kinfo_proc *, VARENT *);
double getpcpu(const struct kinfo_proc *);
double getpmem(const struct kinfo_proc *);
void gname(const struct kinfo_proc *, VARENT *);
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 2941c72375a..1ef756336de 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keyword.c,v 1.43 2015/12/30 14:59:10 tedu Exp $ */
+/* $OpenBSD: keyword.c,v 1.44 2016/09/08 15:11:29 tedu Exp $ */
/* $NetBSD: keyword.c,v 1.12.6.1 1996/05/30 21:25:13 cgd Exp $ */
/*-
@@ -101,7 +101,7 @@ VAR var[] = {
{"cwd", "CWD", NULL, LJUST, curwd, CWDLEN},
{"dsiz", "DSIZ", NULL, 0, dsize, 4},
{"emul", "EMUL", NULL, LJUST, emulname, KI_EMULNAMELEN - 1},
- {"etime", "ELAPSED", "start"},
+ {"etime", "ELAPSED", NULL, USER, elapsed, 12},
{"f", "F", NULL, 0, pvar, 7, 0, POFF(p_flag), INT32, "x"},
{"flags", "", "f"},
GID("gid", "GID", pvar, POFF(p_gid)),
diff --git a/bin/ps/print.c b/bin/ps/print.c
index ecbd0f38821..28e0741f8c6 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.68 2016/09/01 09:44:06 tedu Exp $ */
+/* $OpenBSD: print.c,v 1.69 2016/09/08 15:11:29 tedu Exp $ */
/* $NetBSD: print.c,v 1.27 1995/09/29 21:58:12 cgd Exp $ */
/*-
@@ -439,6 +439,50 @@ lstarted(const struct kinfo_proc *kp, VARENT *ve)
(void)printf("%-*s", v->width, buf);
}
+void elapsed(const struct kinfo_proc *kp, VARENT *ve)
+{
+ VAR *v;
+ static time_t now;
+ time_t secs;
+ char buf[64];
+ long days, hours, minutes, seconds;
+
+ v = ve->var;
+ if (!kp->p_uvalid) {
+ (void)printf("%*s", v->width, "-");
+ return;
+ }
+
+ if (!now)
+ (void)time(&now);
+ secs = now - kp->p_ustart_sec;
+
+ if (secs < 0) {
+ (void)printf("%*s", v->width, "-");
+ return;
+ }
+
+ days = secs / SECSPERDAY;
+ secs %= SECSPERDAY;
+
+ hours = secs / SECSPERHOUR;
+ secs %= SECSPERHOUR;
+
+ minutes = secs / 60;
+ seconds = secs % 60;
+
+ if (days > 0)
+ (void)snprintf(buf, sizeof(buf), "%ld-%02ld:%02ld:%02ld",
+ days, hours, minutes, seconds);
+ else if (hours > 0)
+ (void)snprintf(buf, sizeof(buf), "%02ld:%02ld:%02ld",
+ hours, minutes, seconds);
+ else
+ (void)snprintf(buf, sizeof(buf), "%02ld:%02ld",
+ minutes, seconds);
+ (void)printf("%*s", v->width, buf);
+}
+
void
wchan(const struct kinfo_proc *kp, VARENT *ve)
{
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index a4af6bb314d..2de98b33c66 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ps.1,v 1.106 2016/04/25 20:34:55 jmc Exp $
+.\" $OpenBSD: ps.1,v 1.107 2016/09/08 15:11:30 tedu Exp $
.\" $NetBSD: ps.1,v 1.16 1996/03/21 01:36:28 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
@@ -30,7 +30,7 @@
.\"
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd $Mdocdate: April 25 2016 $
+.Dd $Mdocdate: September 8 2016 $
.Dt PS 1
.Os
.Sh NAME
@@ -211,6 +211,8 @@ Current working directory.
Data size, in Kilobytes.
.It Cm emul
Name of system call emulation environment.
+.It Cm etime
+Elapsed time since the process was started.
.It Cm flags
Alias:
.Cm f .
@@ -386,8 +388,6 @@ Sleep time (in seconds; 127 = infinity).
.It Cm ssiz
Stack size, in Kilobytes.
.It Cm start
-Alias:
-.Cm etime .
The time the command started.
If the command started less than 24 hours ago, the start time is
displayed using the