diff options
author | obrien <obrien@FreeBSD.org> | 1998-12-19 20:09:20 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 1998-12-19 20:09:20 +0000 |
commit | 4146899a25b2f14a75ebaed87a7ecd28e910ee15 (patch) | |
tree | b4ecd9963aa8b59e6088d6464af638a4cee1af17 | |
parent | 25759a95be56bc5395e4a663f1bb7a70d362fc0b (diff) | |
download | FreeBSD-src-4146899a25b2f14a75ebaed87a7ecd28e910ee15.zip FreeBSD-src-4146899a25b2f14a75ebaed87a7ecd28e910ee15.tar.gz |
Display uptime in upper right corner.
Submitted by: Andy Farkas <andyf@speednet.com.au>
Obtained from: freebsd-current list
-rw-r--r-- | contrib/top/display.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/top/display.c b/contrib/top/display.c index 6b3a5f4..bb3be21 100644 --- a/contrib/top/display.c +++ b/contrib/top/display.c @@ -29,6 +29,9 @@ #include "os.h" #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 */ @@ -240,11 +243,51 @@ 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: |