summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/ps/extern.h1
-rw-r--r--bin/ps/print.c6
-rw-r--r--bin/ps/ps.c4
3 files changed, 5 insertions, 6 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index 927343c..4bae792 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -42,6 +42,7 @@ struct varent;
extern fixpt_t ccpu;
extern int cflag, eval, fscale, mempages, nlistread, rawcpu;
extern int sumrusage, termwidth, totwidth;
+extern time_t now;
extern VARENT *vhead;
__BEGIN_DECLS
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 4f43aa4..7864cae 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -376,7 +376,6 @@ void
started(KINFO *k, VARENT *ve)
{
VAR *v;
- static time_t now;
time_t then;
struct tm *tp;
char buf[100];
@@ -393,8 +392,6 @@ started(KINFO *k, VARENT *ve)
then = k->ki_p->ki_start.tv_sec;
tp = localtime(&then);
- if (!now)
- (void)time(&now);
if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
(void)strftime(buf, sizeof(buf) - 1,
use_ampm ? "%l:%M%p" : "%k:%M ", tp);
@@ -541,12 +538,9 @@ elapsed(KINFO *k, VARENT *ve)
VAR *v;
time_t secs;
char obuff[128];
- static time_t now;
v = ve->var;
- if (!now)
- time(&now);
secs = now - k->ki_p->ki_start.tv_sec;
(void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld", secs/60, secs%60);
(void)printf("%*s", v->width, obuff);
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 2a25c92..f808cd5 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -81,6 +81,8 @@ int sumrusage; /* -S */
int termwidth; /* width of screen (0 == infinity) */
int totwidth; /* calculated width of requested variables */
+time_t now; /* current time(3) value */
+
static int needuser, needcomm, needenv;
#if defined(LAZY_PS)
static int forceuread=0;
@@ -128,6 +130,8 @@ main(int argc, char *argv[])
const char *nlistf, *memf;
(void) setlocale(LC_ALL, "");
+ /* Set the time to what it is right now. */
+ time(&now);
if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0')
termwidth = atoi(cols);
OpenPOWER on IntegriCloud