1*45139Sbostic /*- 2*45139Sbostic * Copyright (c) 1990 The Regents of the University of California. 3*45139Sbostic * All rights reserved. 4*45139Sbostic * 5*45139Sbostic * %sccs.include.redist.c% 621334Sdist */ 712843Ssam 826521Sdonn #if defined(LIBC_SCCS) && !defined(lint) 9*45139Sbostic static char sccsid[] = "@(#)times.c 5.3 (Berkeley) 08/27/90"; 10*45139Sbostic #endif /* LIBC_SCCS and not lint */ 1121334Sdist 1212843Ssam #include <sys/time.h> 13*45139Sbostic #include <sys/times.h> 1412843Ssam #include <sys/resource.h> 1512843Ssam 16*45139Sbostic clock_t 1712843Ssam times(tmsp) 1812887Ssam register struct tms *tmsp; 1912843Ssam { 2012843Ssam struct rusage ru; 21*45139Sbostic clock_t scale60(); 2212843Ssam 2312843Ssam if (getrusage(RUSAGE_SELF, &ru) < 0) 24*45139Sbostic return ((clock_t)-1); 2512887Ssam tmsp->tms_utime = scale60(&ru.ru_utime); 2612843Ssam tmsp->tms_stime = scale60(&ru.ru_stime); 2712843Ssam if (getrusage(RUSAGE_CHILDREN, &ru) < 0) 28*45139Sbostic return ((clock_t)-1); 2912843Ssam tmsp->tms_cutime = scale60(&ru.ru_utime); 3012843Ssam tmsp->tms_cstime = scale60(&ru.ru_stime); 31*45139Sbostic return ((clock_t)0); 3212843Ssam } 3312843Ssam 34*45139Sbostic static clock_t 3512843Ssam scale60(tvp) 3612843Ssam register struct timeval *tvp; 3712843Ssam { 3812843Ssam return (tvp->tv_sec * 60 + tvp->tv_usec / 16667); 3912843Ssam } 40