1 /* Return CPU and real time used by process and its children. Hurd version.
2 Copyright (C) 2001-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
21 #include <sys/resource.h>
22 #include <sys/times.h>
26 #include <mach/task_info.h>
30 clock_from_time_value (const time_value_t
*t
)
32 return t
->seconds
* 1000000 + t
->microseconds
;
35 /* Store the CPU time used by this process and all its
36 dead children (and their dead children) in BUFFER.
37 Return the elapsed real time, or (clock_t) -1 for errors.
38 All times are in CLK_TCKths of a second. */
40 __times (struct tms
*tms
)
42 struct task_basic_info bi
;
43 struct task_thread_times_info tti
;
44 mach_msg_type_number_t count
;
48 count
= TASK_BASIC_INFO_COUNT
;
49 err
= __task_info (__mach_task_self (), TASK_BASIC_INFO
,
50 (task_info_t
) &bi
, &count
);
52 return __hurd_fail (err
);
54 count
= TASK_THREAD_TIMES_INFO_COUNT
;
55 err
= __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO
,
56 (task_info_t
) &tti
, &count
);
58 return __hurd_fail (err
);
60 tms
->tms_utime
= (clock_from_time_value (&bi
.user_time
)
61 + clock_from_time_value (&tti
.user_time
));
62 tms
->tms_stime
= (clock_from_time_value (&bi
.system_time
)
63 + clock_from_time_value (&tti
.system_time
));
65 /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be. */
66 tms
->tms_cutime
= tms
->tms_cstime
= 0;
68 __host_get_time (__mach_host_self (), &now
);
70 return (clock_from_time_value (&now
)
71 - clock_from_time_value (&bi
.creation_time
));
73 weak_alias (__times
, times
)