4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1995-1997, by Sun Microsystems, Inc.
24 * All rights reserved.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 /* Portions Copyright(c) 1988, Sun Microsystems Inc. */
32 /* All Rights Reserved */
34 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
39 * Compatibility lib for SunOS's wait4().
42 #include <sys/types.h>
44 #include <sys/times.h>
46 #include <sys/siginfo.h>
47 #include <sys/procset.h>
48 #include <sys/param.h>
49 #include <sys/resource.h>
55 * Since sysV does not support rusage as in BSD, an approximate approach
60 * if ( a child is found )
62 * rusage ~= diff in the 2 times call
69 static int wstat(int, int);
72 wait4(pid_t pid
, int *status
, int options
, struct rusage
*rp
)
74 struct tms before_tms
;
81 if ((long)status
== -1L || (long)rp
== -1L) {
87 (void) memset(rp
, 0, sizeof (struct rusage
));
88 (void) memset(&info
, 0, sizeof (siginfo_t
));
89 if (times(&before_tms
) < 0)
90 return (-1); /* errno is set by times() */
93 * SunOS's wait4() only supports WNOHANG & WUNTRACED
95 if (options
& ~(WNOHANG
|WUNTRACED
))
96 return (EINVAL
); /* used to be done by the kernel */
97 noptions
= options
| WEXITED
| WTRAPPED
;
100 * Emulate undocumented 4.x semantics for 1186845
110 error
= waitid(idtype
, pid
, &info
, noptions
);
112 clock_t diffu
; /* difference in usertime (ticks) */
113 clock_t diffs
; /* difference in systemtime (ticks) */
115 if ((options
& WNOHANG
) && (info
.si_pid
== 0))
116 return (0); /* no child found */
119 if (times(&after_tms
) < 0)
120 return (-1); /* errno set by times() */
122 * The system/user time is an approximation only !!!
124 diffu
= after_tms
.tms_cutime
- before_tms
.tms_cutime
;
125 diffs
= after_tms
.tms_cstime
- before_tms
.tms_cstime
;
126 rp
->ru_utime
.tv_sec
= diffu
/ HZ
;
127 rp
->ru_utime
.tv_usec
= (diffu
% HZ
) * (1000000 / HZ
);
128 rp
->ru_stime
.tv_sec
= diffs
/ HZ
;
129 rp
->ru_stime
.tv_usec
= (diffs
% HZ
) * (1000000 / HZ
);
132 *status
= wstat(info
.si_code
, info
.si_status
);
133 return (info
.si_pid
);
135 return (-1); /* error number is set by waitid() */
140 * Convert the status code to old style wait status
143 wstat(int code
, int status
)
145 int stat
= (status
& 0377);