1/*
2 * Copyright 2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Bruno Albuquerque, bga@bug-br.org.br
7 */
8
9#include <OS.h>
10
11#include <sys/resource.h>
12#include <sys/wait.h>
13
14
15pid_t
16wait3(int *status, int options, struct rusage *rusage)
17{
18	return wait4(-1, status, options, rusage);
19}
20
21
22pid_t
23wait4(pid_t pid, int *status, int options, struct rusage *rusage)
24{
25	pid_t waitPid = waitpid(pid, status, options);
26	if (waitPid != -1) {
27		team_usage_info info;
28
29		// Obtain info for the process that changed state.
30		if (get_team_usage_info(waitPid, RUSAGE_SELF, &info) != B_OK)
31			return -1;
32
33		rusage->ru_utime.tv_sec = info.user_time / 1000000;
34		rusage->ru_utime.tv_usec = info.user_time % 1000000;
35
36		rusage->ru_stime.tv_sec = info.kernel_time / 1000000;
37		rusage->ru_stime.tv_usec = info.kernel_time % 1000000;
38	}
39
40	return waitPid;
41}
42
43