1 /* Copyright (C) 1991,92,93,95,96,97,1998,2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <sys/resource.h>
22 #include <sys/times.h>
27 /* Time the program started. */
28 extern time_t _posix_start_time
;
34 timeval_to_clock_t (const struct timeval
*tv
, clock_t clk_tck
)
36 return (clock_t) ((tv
->tv_sec
* clk_tck
) +
37 (tv
->tv_usec
* clk_tck
/ 1000000L));
40 /* Store the CPU time used by this process and all its
41 dead children (and their dead children) in BUFFER.
42 Return the elapsed real time, or (clock_t) -1 for errors.
43 All times are in CLK_TCKths of a second. */
57 clk_tck
= __getclktck ();
59 if (__getrusage (RUSAGE_SELF
, &usage
) < 0)
61 buffer
->tms_utime
= (clock_t) timeval_to_clock_t (&usage
.ru_utime
, clk_tck
);
62 buffer
->tms_stime
= (clock_t) timeval_to_clock_t (&usage
.ru_stime
, clk_tck
);
64 if (__getrusage (RUSAGE_CHILDREN
, &usage
) < 0)
66 buffer
->tms_cutime
= (clock_t) timeval_to_clock_t (&usage
.ru_utime
, clk_tck
);
67 buffer
->tms_cstime
= (clock_t) timeval_to_clock_t (&usage
.ru_stime
, clk_tck
);
69 return (time ((time_t *) NULL
) - _posix_start_time
) * clk_tck
;
72 weak_alias (__times
, times
)