summaryrefslogtreecommitdiffstats
path: root/contrib/top
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>1999-01-09 20:25:02 +0000
committerobrien <obrien@FreeBSD.org>1999-01-09 20:25:02 +0000
commit5ef1fe5a746e1c0d94e728b671737d381e878511 (patch)
treea3ebc7a1920ec766658c787379ec3c7b26cbaeea /contrib/top
parent48d88654f8eeed779ba34dafaa48e1f50e96008e (diff)
downloadFreeBSD-src-5ef1fe5a746e1c0d94e728b671737d381e878511.zip
FreeBSD-src-5ef1fe5a746e1c0d94e728b671737d381e878511.tar.gz
uptime display more in style with original code
Diffstat (limited to 'contrib/top')
-rw-r--r--contrib/top/display.c77
-rw-r--r--contrib/top/machine.h1
-rw-r--r--contrib/top/top.c1
3 files changed, 37 insertions, 42 deletions
diff --git a/contrib/top/display.c b/contrib/top/display.c
index bb3be21..09c5d64 100644
--- a/contrib/top/display.c
+++ b/contrib/top/display.c
@@ -30,8 +30,6 @@
#include <ctype.h>
#include <time.h>
#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
#include "screen.h" /* interface to screen package */
#include "layout.h" /* defines for screen position layout */
@@ -243,51 +241,11 @@ double *avenrun;
}
}
-struct timeval boottime;
-time_t now;
-time_t uptime;
-
i_timeofday(tod)
time_t *tod;
{
- int days, hrs, i, mins, secs;
- int mib[2];
- size_t size;
-
- (void)time(&now);
-
- /*
- * Print how long system has been up.
- * (Found by looking getting "boottime" from the kernel)
- */
- mib[0] = CTL_KERN;
- mib[1] = KERN_BOOTTIME;
- size = sizeof(boottime);
- if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
- boottime.tv_sec != 0) {
- uptime = now - boottime.tv_sec;
- uptime += 30;
- days = uptime / 86400;
- uptime %= 86400;
- hrs = uptime / 3600;
- uptime %= 3600;
- mins = uptime / 60;
- secs = uptime % 60;
-
- if (smart_terminal)
- {
- Move_to((screen_width - 24) - (days > 9 ? 1 : 0), 0);
- }
- else
- {
- fputs(" ", stdout);
- }
-
- printf(" up %d+%02d:%02d:%02d", days, hrs, mins, secs);
- }
-
/*
* Display the current time.
* "ctime" always returns a string that looks like this:
@@ -1211,3 +1169,38 @@ char *str;
}
return(str);
}
+
+i_uptime(bt, tod)
+
+struct timeval* bt;
+time_t *tod;
+
+{
+ time_t uptime;
+ int days, hrs, mins, secs;
+
+ if (bt->tv_sec != -1) {
+ uptime = *tod - bt->tv_sec;
+ uptime += 30;
+ days = uptime / 86400;
+ uptime %= 86400;
+ hrs = uptime / 3600;
+ uptime %= 3600;
+ mins = uptime / 60;
+ secs = uptime % 60;
+
+ /*
+ * Display the uptime.
+ */
+
+ if (smart_terminal)
+ {
+ Move_to((screen_width - 24) - (days > 9 ? 1 : 0), 0);
+ }
+ else
+ {
+ fputs(" ", stdout);
+ }
+ printf(" up %d+%02d:%02d:%02d", days, hrs, mins, secs);
+ }
+}
diff --git a/contrib/top/machine.h b/contrib/top/machine.h
index 0a9953f..0f14bf3 100644
--- a/contrib/top/machine.h
+++ b/contrib/top/machine.h
@@ -32,6 +32,7 @@ struct system_info
int *cpustates;
int *memory;
int *swap;
+ struct timeval boottime;
};
/* cpu_states is an array of percentages * 10. For example,
diff --git a/contrib/top/top.c b/contrib/top/top.c
index ef4b963..51cd3f0 100644
--- a/contrib/top/top.c
+++ b/contrib/top/top.c
@@ -549,6 +549,7 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
/* display the current time */
/* this method of getting the time SHOULD be fairly portable */
time(&curr_time);
+ i_uptime(&system_info.boottime, &curr_time);
i_timeofday(&curr_time);
/* display process state breakdown */
OpenPOWER on IntegriCloud