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:
asomers 2018-05-04 14:39:32 +00:00
parent 0dbea2eefe
commit b827a65241

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");