From owner-freebsd-current Sat Dec 19 01:58:26 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id BAA19591 for freebsd-current-outgoing; Sat, 19 Dec 1998 01:58:26 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from backup.af.speednet.com.au (af.speednet.com.au [202.135.206.244]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id BAA19585 for ; Sat, 19 Dec 1998 01:58:22 -0800 (PST) (envelope-from andyf@speednet.com.au) Received: from backup.zippynet.iol.net.au (backup.zippynet.iol.net.au [172.22.2.4]) by backup.af.speednet.com.au (8.9.1/8.9.1) with ESMTP id UAA15663 for ; Sat, 19 Dec 1998 20:58:04 +1100 (EST) Date: Sat, 19 Dec 1998 20:58:04 +1100 (EST) From: Andy Farkas X-Sender: andyf@backup.zippynet.iol.net.au To: freebsd-current@FreeBSD.ORG Subject: an addition to top(1) Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I've always thought that top(1) should display the system uptime. Here's a patch. The code was cut straight out of /usr/src/usr.bin/w/w.c Merry Christmas! # cd /usr/src/contrib/top # rcsdiff -r1.1 -u display.c =================================================================== RCS file: display.c,v retrieving revision 1.1 diff -u -r1.1 display.c --- display.c 1998/12/18 02:23:39 1.1 +++ display.c 1998/12/19 09:12:03 @@ -30,6 +30,10 @@ #include #include +#include +#include +#include + #include "screen.h" /* interface to screen package */ #include "layout.h" /* defines for screen position layout */ #include "display.h" @@ -240,11 +244,51 @@ } } +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: -- :{ andyf@speednet.com.au Andy Farkas System Administrator Speed Internet Services http://www.speednet.com.au/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message