wait4.c revision a574db851cdc636fc3939b68e80d79fe7fbd57f2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
* All Rights Reserved
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "synonyms.h"
/*
* Compatibility lib for SunOS's wait4().
*/
#include <wait.h>
#include <sys/resource.h>
#include <string.h>
#include <errno.h>
/*
* Since sysV does not support rusage as in BSD, an approximate approach
* is:
* ...
* call times
* call waitid
* if ( a child is found )
* call times again
* rusage ~= diff in the 2 times call
* ...
*/
static int wstat(int, int);
{
struct tms before_tms;
int error;
int noptions;
if (rp)
return (-1); /* errno is set by times() */
/*
* SunOS's wait4() previously supported only WNOHANG &
* WUNTRACED. XPG4v2 mandates that wait3() (which calls
* wait4()) also support WCONTINUED.
*/
return (-1);
}
/*
* Emulate undocumented 4.x semantics for 1186845
*/
if (pid < 0) {
} else if (pid == 0)
else
if (error == 0) {
return (0); /* no child found */
if (rp) {
return (-1); /* errno set by times() */
/*
*/
}
if (status)
} else {
return (-1); /* error number is set by waitid() */
}
}
/*
* Convert the status code to old style wait status
*/
static int
{
switch (code) {
case CLD_EXITED:
stat <<= 8;
break;
case CLD_DUMPED:
break;
case CLD_KILLED:
break;
case CLD_TRAPPED:
case CLD_STOPPED:
stat <<= 8;
break;
case CLD_CONTINUED:
break;
}
return (stat);
}