time(1): use the monotonic clock

The monotonic clock is more appropriate than the realtime clock for
measuring durations.

Reviewed by:	ken, jilles
Differential Revision:	https://reviews.freebsd.org/D14032
This commit is contained in:
Alan Somers 2018-05-04 14:39:32 +00:00
parent 6d5127daf4
commit 8a9ab04279
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=333251

View File

@ -121,7 +121,7 @@ main(int argc, char **argv)
setvbuf(out, (char *)NULL, _IONBF, (size_t)0);
}
if (clock_gettime(CLOCK_REALTIME, &before_ts))
if (clock_gettime(CLOCK_MONOTONIC, &before_ts))
err(1, "clock_gettime");
switch(pid = fork()) {
case -1: /* error */
@ -141,13 +141,13 @@ main(int argc, char **argv)
while (wait4(pid, &status, 0, &ru) != pid) {
if (siginfo_recvd) {
siginfo_recvd = 0;
if (clock_gettime(CLOCK_REALTIME, &after))
if (clock_gettime(CLOCK_MONOTONIC, &after))
err(1, "clock_gettime");
getrusage(RUSAGE_CHILDREN, &ru);
showtime(stdout, &before_ts, &after, &ru);
}
}
if (clock_gettime(CLOCK_REALTIME, &after))
if (clock_gettime(CLOCK_MONOTONIC, &after))
err(1, "clock_gettime");
if ( ! WIFEXITED(status))
warnx("command terminated abnormally");