diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c index ebb4a4fff24e..e911d8c649d8 100644 --- a/usr.bin/time/time.c +++ b/usr.bin/time/time.c @@ -45,8 +45,13 @@ static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#include + +#include #include +static int getstathz __P((void)); + main(argc, argv) int argc; char **argv; @@ -102,7 +107,7 @@ main(argc, argv) fprintf(stderr, "%9ld.%02ld sys\n", ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000); if (lflag) { - int hz = 100; /* XXX */ + int hz = getstathz(); u_long ticks; ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) + @@ -146,3 +151,21 @@ main(argc, argv) } exit (status>>8); } + +/* + * Return the frequency of the kernel's statistics clock. + */ +static int +getstathz() +{ + struct clockinfo clockrate; + int mib[2]; + size_t size; + + mib[0] = CTL_KERN; + mib[1] = KERN_CLOCKRATE; + size = sizeof clockrate; + if (sysctl(mib, 2, &clockrate, &size, NULL, 0) == -1) + err(1, "sysctl kern.clockrate"); + return clockrate.stathz; +}