/*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * %sccs.include.redist.c% */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)times.c 8.1 (Berkeley) 06/04/93"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include /* * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, * but this would overflow if we switch to nanosec. */ #define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) clock_t times(tp) register struct tms *tp; { struct rusage ru; struct timeval t; 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 (gettimeofday(&t, (struct timezone *)0)) return ((clock_t)-1); return ((clock_t)(CONVTCK(t))); }