1*21334Sdist /* 2*21334Sdist * Copyright (c) 1980 Regents of the University of California. 3*21334Sdist * All rights reserved. The Berkeley software License Agreement 4*21334Sdist * specifies the terms and conditions for redistribution. 5*21334Sdist */ 612843Ssam 7*21334Sdist #ifndef lint 8*21334Sdist static char sccsid[] = "@(#)times.c 5.1 (Berkeley) 05/30/85"; 9*21334Sdist #endif not lint 10*21334Sdist 1112843Ssam #include <sys/time.h> 1212843Ssam #include <sys/resource.h> 1312843Ssam 1412843Ssam /* 1512843Ssam * Backwards compatible times. 1612843Ssam */ 1712843Ssam struct tms { 1812843Ssam int tms_utime; /* user time */ 1912843Ssam int tms_stime; /* system time */ 2012843Ssam int tms_cutime; /* user time, children */ 2112843Ssam int tms_cstime; /* system time, children */ 2212843Ssam }; 2312843Ssam 2412843Ssam times(tmsp) 2512887Ssam register struct tms *tmsp; 2612843Ssam { 2712843Ssam struct rusage ru; 2812843Ssam 2912843Ssam if (getrusage(RUSAGE_SELF, &ru) < 0) 3012843Ssam return (-1); 3112887Ssam tmsp->tms_utime = scale60(&ru.ru_utime); 3212843Ssam tmsp->tms_stime = scale60(&ru.ru_stime); 3312843Ssam if (getrusage(RUSAGE_CHILDREN, &ru) < 0) 3412843Ssam return (-1); 3512843Ssam tmsp->tms_cutime = scale60(&ru.ru_utime); 3612843Ssam tmsp->tms_cstime = scale60(&ru.ru_stime); 3712843Ssam return (0); 3812843Ssam } 3912843Ssam 4012843Ssam static 4112843Ssam scale60(tvp) 4212843Ssam register struct timeval *tvp; 4312843Ssam { 4412843Ssam 4512843Ssam return (tvp->tv_sec * 60 + tvp->tv_usec / 16667); 4612843Ssam } 47