197718Smike/*- 214475Shsu * Copyright (c) 1982, 1986, 1989, 1993, 1994 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 2914475Shsu * @(#)wait.h 8.2 (Berkeley) 7/10/94 3050477Speter * $FreeBSD$ 311541Srgrimes */ 321541Srgrimes 332165Spaul#ifndef _SYS_WAIT_H_ 342165Spaul#define _SYS_WAIT_H_ 352165Spaul 3697851Smike#include <sys/cdefs.h> 3797851Smike 381541Srgrimes/* 3997718Smike * This file holds definitions relevant to the wait4 system call and the 4097718Smike * alternate interfaces that use it (wait, wait3, waitpid). 411541Srgrimes */ 421541Srgrimes 431541Srgrimes/* 4497718Smike * Macros to test the exit status returned by wait and extract the relevant 4597718Smike * values. 461541Srgrimes */ 4797725Smike#if __BSD_VISIBLE 481541Srgrimes#define WCOREFLAG 0200 49152260Sdavidxu#endif 5097725Smike#define _W_INT(i) (i) 511541Srgrimes 521541Srgrimes#define _WSTATUS(x) (_W_INT(x) & 0177) 531541Srgrimes#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ 5497718Smike#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED) 5597718Smike#define WSTOPSIG(x) (_W_INT(x) >> 8) 56254218Sjilles#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0 && (x) != 0x13) 5797718Smike#define WTERMSIG(x) (_WSTATUS(x)) 5897718Smike#define WIFEXITED(x) (_WSTATUS(x) == 0) 5997718Smike#define WEXITSTATUS(x) (_W_INT(x) >> 8) 6097714Smike#define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */ 6197725Smike#if __BSD_VISIBLE 6297718Smike#define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) 631541Srgrimes 641541Srgrimes#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) 651541Srgrimes#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) 661541Srgrimes#endif 671541Srgrimes 681541Srgrimes/* 691541Srgrimes * Option bits for the third argument of wait4. WNOHANG causes the 701541Srgrimes * wait to not hang if there are no stopped or terminated processes, rather 711541Srgrimes * returning an error indication in this case (pid==0). WUNTRACED 721541Srgrimes * indicates that the caller should receive status about untraced children 731541Srgrimes * which stop due to signals. If children are stopped and a wait without 741541Srgrimes * this option is done, it is as though they were still running... nothing 75182193Skib * about them is returned. WNOWAIT only request information about zombie, 76182193Skib * leaving the proc around, available for later waits. 771541Srgrimes */ 7897718Smike#define WNOHANG 1 /* Don't hang in wait. */ 7997718Smike#define WUNTRACED 2 /* Tell about stopped, untraced children. */ 80182193Skib#define WSTOPPED WUNTRACED /* SUS compatibility */ 8197714Smike#define WCONTINUED 4 /* Report a job control continued process. */ 82182193Skib#define WNOWAIT 8 /* Poll only. Don't delete the proc entry. */ 83242958Skib#define WEXITED 16 /* Wait for exited processes. */ 84242958Skib#define WTRAPPED 32 /* Wait for a process to hit a trap or 85242958Skib a breakpoint. */ 8697725Smike 8797725Smike#if __BSD_VISIBLE 8897718Smike#define WLINUXCLONE 0x80000000 /* Wait for kthread spawned from linux_clone. */ 8997725Smike#endif 901541Srgrimes 91243135Skib#ifndef _IDTYPE_T_DECLARED 92243135Skibtypedef enum 93243135Skib#if __BSD_VISIBLE 94243135Skib idtype /* pollutes XPG4.2 namespace */ 95243135Skib#endif 96243135Skib { 97243135Skib /* 98243135Skib * These names were mostly lifted from Solaris source code and 99243135Skib * still use Solaris style naming to avoid breaking any 100243135Skib * OpenSolaris code which has been ported to FreeBSD. There 101243135Skib * is no clear FreeBSD counterpart for all of the names, but 102243135Skib * some have a clear correspondence to FreeBSD entities. 103243135Skib * 104243135Skib * The numerical values are kept synchronized with the Solaris 105243135Skib * values. 106243135Skib */ 107243135Skib P_PID, /* A process identifier. */ 108243135Skib P_PPID, /* A parent process identifier. */ 109243135Skib P_PGID, /* A process group identifier. */ 110243135Skib P_SID, /* A session identifier. */ 111243135Skib P_CID, /* A scheduling class identifier. */ 112243135Skib P_UID, /* A user identifier. */ 113243135Skib P_GID, /* A group identifier. */ 114243135Skib P_ALL, /* All processes. */ 115243135Skib P_LWPID, /* An LWP identifier. */ 116243135Skib P_TASKID, /* A task identifier. */ 117243135Skib P_PROJID, /* A project identifier. */ 118243135Skib P_POOLID, /* A pool identifier. */ 119243135Skib P_JAILID, /* A zone identifier. */ 120243135Skib P_CTID, /* A (process) contract identifier. */ 121243135Skib P_CPUID, /* CPU identifier. */ 122243135Skib P_PSETID /* Processor set identifier. */ 123243135Skib} idtype_t; /* The type of id_t we are using. */ 124243135Skib 125243135Skib#if __BSD_VISIBLE 126243135Skib#define P_ZONEID P_JAILID 127243135Skib#endif 128243135Skib#define _IDTYPE_T_DECLARED 129243135Skib#endif 130243135Skib 1311541Srgrimes/* 1321541Srgrimes * Tokens for special values of the "pid" parameter to wait4. 133242958Skib * Extended struct __wrusage to collect rusage for both the target 134242958Skib * process and its children within one wait6() call. 1351541Srgrimes */ 13697851Smike#if __BSD_VISIBLE 1371541Srgrimes#define WAIT_ANY (-1) /* any process */ 1381541Srgrimes#define WAIT_MYPGRP 0 /* any process in my process group */ 13997725Smike#endif /* __BSD_VISIBLE */ 1401541Srgrimes 141139739Sjhb#ifndef _KERNEL 1421541Srgrimes#include <sys/types.h> 1431541Srgrimes 1441541Srgrimes__BEGIN_DECLS 145242958Skibstruct __siginfo; 14692719Salfredpid_t wait(int *); 14792719Salfredpid_t waitpid(pid_t, int *, int); 148242958Skib#if __POSIX_VISIBLE >= 200112 149242958Skibint waitid(idtype_t, id_t, struct __siginfo *, int); 150242958Skib#endif 15197725Smike#if __BSD_VISIBLE 152128051Sbdestruct rusage; 153242958Skibstruct __wrusage; 15492719Salfredpid_t wait3(int *, int, struct rusage *); 15592719Salfredpid_t wait4(pid_t, int *, int, struct rusage *); 156242958Skibpid_t wait6(idtype_t, id_t, int *, int, struct __wrusage *, 157242958Skib struct __siginfo *); 1581541Srgrimes#endif 1591541Srgrimes__END_DECLS 160139739Sjhb#endif /* !_KERNEL */ 1612165Spaul 16297725Smike#endif /* !_SYS_WAIT_H_ */ 163