diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2001-06-13 13:46:55 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2001-06-13 13:46:55 +0000 |
commit | 4319b6ed4d8be5c4c0a860b5c681785cdc47b76b (patch) | |
tree | 70c0142459f530570491d003877e2127fe0bae05 | |
parent | a39deb81356626a2d4892e9e1e72b74f1e13e2ae (diff) |
Correctly get 'hz' with sysctl. Don't assume it's 100 (it's not on alpha).
-rw-r--r-- | usr.bin/time/time.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c index ae72348d044..c4b9d9c19cd 100644 --- a/usr.bin/time/time.c +++ b/usr.bin/time/time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: time.c,v 1.6 2000/04/29 16:46:36 millert Exp $ */ +/* $OpenBSD: time.c,v 1.7 2001/06/13 13:46:54 art Exp $ */ /* $NetBSD: time.c,v 1.7 1995/06/27 00:34:00 jtc Exp $ */ /* @@ -44,13 +44,14 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: time.c,v 1.6 2000/04/29 16:46:36 millert Exp $"; +static char rcsid[] = "$OpenBSD: time.c,v 1.7 2001/06/13 13:46:54 art Exp $"; #endif /* not lint */ -#include <sys/types.h> +#include <sys/param.h> #include <sys/time.h> #include <sys/resource.h> #include <sys/wait.h> +#include <sys/sysctl.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -134,8 +135,19 @@ main(argc, argv) } if (lflag) { - int hz = 100; /* XXX */ + int hz; long ticks; + int mib[2]; + struct clockinfo clkinfo; + size_t size; + + mib[0] = CTL_KERN; + mib[1] = KERN_CLOCKRATE; + size = sizeof(clkinfo); + if (sysctl(mib, 2, &clkinfo, &size, NULL, 0) < 0) + err(1, "sysctl"); + + hz = clkinfo.hz; ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) + hz * (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) / 1000000; |