clock_t clock() { struct rusage ru; if (getrusage(RUSAGE_SELF, &ru)) return ((clock_t) -1); return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime)))); }
clock_t times(struct tms *tp) { struct rusage ru; struct timespec ts; if (getrusage(RUSAGE_SELF, &ru) < 0) return ((clock_t)-1); tp->tms_utime = CONVTCK(ru.ru_utime); tp->tms_stime = CONVTCK(ru.ru_stime); if (getrusage(RUSAGE_CHILDREN, &ru) < 0) return ((clock_t)-1); tp->tms_cutime = CONVTCK(ru.ru_utime); tp->tms_cstime = CONVTCK(ru.ru_stime); if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) return ((clock_t)-1); return (ts.tv_sec * CLK_TCK + ts.tv_nsec / (1000000000 / CLK_TCK)); }