Commit | Line | Data |
---|---|---|
5f6134e7 KB |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
bb0cfa24 DF |
6 | */ |
7 | ||
2ce81398 | 8 | #if defined(LIBC_SCCS) && !defined(lint) |
d119f206 | 9 | static char sccsid[] = "@(#)times.c 5.4 (Berkeley) %G%"; |
5f6134e7 | 10 | #endif /* LIBC_SCCS and not lint */ |
9af2a874 | 11 | |
d119f206 | 12 | #include <sys/param.h> |
9af2a874 | 13 | #include <sys/time.h> |
5f6134e7 | 14 | #include <sys/times.h> |
9af2a874 SL |
15 | #include <sys/resource.h> |
16 | ||
d119f206 KB |
17 | /* |
18 | * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, | |
19 | * but this would overflow if we switch to nanosec. | |
20 | */ | |
21 | #define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) | |
22 | ||
5f6134e7 | 23 | clock_t |
d119f206 KB |
24 | times(tp) |
25 | register struct tms *tp; | |
9af2a874 SL |
26 | { |
27 | struct rusage ru; | |
d119f206 | 28 | struct timeval t; |
9af2a874 SL |
29 | |
30 | if (getrusage(RUSAGE_SELF, &ru) < 0) | |
5f6134e7 | 31 | return ((clock_t)-1); |
d119f206 KB |
32 | tp->tms_utime = CONVTCK(ru.ru_utime); |
33 | tp->tms_stime = CONVTCK(ru.ru_stime); | |
9af2a874 | 34 | if (getrusage(RUSAGE_CHILDREN, &ru) < 0) |
5f6134e7 | 35 | return ((clock_t)-1); |
d119f206 KB |
36 | tp->tms_cutime = CONVTCK(ru.ru_utime); |
37 | tp->tms_cstime = CONVTCK(ru.ru_stime); | |
38 | if (gettimeofday(&t, (struct timezone *)0)) | |
39 | return ((clock_t)-1); | |
40 | return ((clock_t)(CONVTCK(t))); | |
9af2a874 | 41 | } |