1 /* getrusage -- Get resource usage information about processes. Hurd version.
2 Copyright (C) 1999,2001 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <sys/resource.h>
24 #include <mach/task_info.h>
27 /* Return resource usage information on process indicated by WHO
28 and put it in *USAGE. Returns 0 for success, -1 for failure. */
30 __getrusage (who
, usage
)
31 enum __rusage_who who
;
34 struct task_basic_info bi
;
35 struct task_events_info ei
;
36 struct task_thread_times_info tti
;
37 mach_msg_type_number_t count
;
43 count
= TASK_BASIC_INFO_COUNT
;
44 err
= __task_info (__mach_task_self (), TASK_BASIC_INFO
,
45 (task_info_t
) &bi
, &count
);
47 return __hurd_fail (err
);
49 count
= TASK_EVENTS_INFO_COUNT
;
50 err
= __task_info (__mach_task_self (), TASK_EVENTS_INFO
,
51 (task_info_t
) &ei
, &count
);
52 if (err
== KERN_INVALID_ARGUMENT
) /* microkernel doesn't implement it */
53 memset (&ei
, 0, sizeof ei
);
55 return __hurd_fail (err
);
57 count
= TASK_THREAD_TIMES_INFO_COUNT
;
58 err
= __task_info (__mach_task_self (), TASK_THREAD_TIMES_INFO
,
59 (task_info_t
) &tti
, &count
);
61 return __hurd_fail (err
);
63 time_value_add (&bi
.user_time
, &tti
.user_time
);
64 time_value_add (&bi
.system_time
, &tti
.system_time
);
66 memset (usage
, 0, sizeof (struct rusage
));
68 usage
->ru_utime
.tv_sec
= bi
.user_time
.seconds
;
69 usage
->ru_utime
.tv_usec
= bi
.user_time
.microseconds
;
70 usage
->ru_stime
.tv_sec
= bi
.system_time
.seconds
;
71 usage
->ru_stime
.tv_usec
= bi
.system_time
.microseconds
;
73 /* These statistics map only approximately. */
74 usage
->ru_majflt
= ei
.pageins
;
75 usage
->ru_minflt
= ei
.faults
- ei
.pageins
;
76 usage
->ru_msgsnd
= ei
.messages_sent
; /* Mach IPC, not SysV IPC */
77 usage
->ru_msgrcv
= ei
.messages_received
; /* Mach IPC, not SysV IPC */
81 /* XXX Not implemented yet. However, zero out USAGE to be
82 consistent with the wait3 and wait4 functions. */
83 memset (usage
, 0, sizeof (struct rusage
));
94 weak_alias (__getrusage
, getrusage
)