1a9643ea8Slogwang /*- 2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-3-Clause 3*22ce4affSfengbojiang * 4a9643ea8Slogwang * Copyright (c) 1982, 1986, 1989, 1993, 1994 5a9643ea8Slogwang * The Regents of the University of California. All rights reserved. 6a9643ea8Slogwang * 7a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without 8a9643ea8Slogwang * modification, are permitted provided that the following conditions 9a9643ea8Slogwang * are met: 10a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright 11a9643ea8Slogwang * notice, this list of conditions and the following disclaimer. 12a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright 13a9643ea8Slogwang * notice, this list of conditions and the following disclaimer in the 14a9643ea8Slogwang * documentation and/or other materials provided with the distribution. 15*22ce4affSfengbojiang * 3. Neither the name of the University nor the names of its contributors 16a9643ea8Slogwang * may be used to endorse or promote products derived from this software 17a9643ea8Slogwang * without specific prior written permission. 18a9643ea8Slogwang * 19a9643ea8Slogwang * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21a9643ea8Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22a9643ea8Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23a9643ea8Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24a9643ea8Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25a9643ea8Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26a9643ea8Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27a9643ea8Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28a9643ea8Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29a9643ea8Slogwang * SUCH DAMAGE. 30a9643ea8Slogwang * 31a9643ea8Slogwang * @(#)wait.h 8.2 (Berkeley) 7/10/94 32a9643ea8Slogwang * $FreeBSD$ 33a9643ea8Slogwang */ 34a9643ea8Slogwang 35a9643ea8Slogwang #ifndef _SYS_WAIT_H_ 36a9643ea8Slogwang #define _SYS_WAIT_H_ 37a9643ea8Slogwang 38a9643ea8Slogwang #include <sys/cdefs.h> 39a9643ea8Slogwang 40a9643ea8Slogwang /* 41a9643ea8Slogwang * This file holds definitions relevant to the wait4 system call and the 42a9643ea8Slogwang * alternate interfaces that use it (wait, wait3, waitpid). 43a9643ea8Slogwang */ 44a9643ea8Slogwang 45a9643ea8Slogwang /* 46a9643ea8Slogwang * Macros to test the exit status returned by wait and extract the relevant 47a9643ea8Slogwang * values. 48a9643ea8Slogwang */ 49a9643ea8Slogwang #if __BSD_VISIBLE 50a9643ea8Slogwang #define WCOREFLAG 0200 51a9643ea8Slogwang #endif 52a9643ea8Slogwang #define _W_INT(i) (i) 53a9643ea8Slogwang 54a9643ea8Slogwang #define _WSTATUS(x) (_W_INT(x) & 0177) 55a9643ea8Slogwang #define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ 56a9643ea8Slogwang #define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED) 57a9643ea8Slogwang #define WSTOPSIG(x) (_W_INT(x) >> 8) 58a9643ea8Slogwang #define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0 && (x) != 0x13) 59a9643ea8Slogwang #define WTERMSIG(x) (_WSTATUS(x)) 60a9643ea8Slogwang #define WIFEXITED(x) (_WSTATUS(x) == 0) 61a9643ea8Slogwang #define WEXITSTATUS(x) (_W_INT(x) >> 8) 62a9643ea8Slogwang #define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */ 63a9643ea8Slogwang #if __BSD_VISIBLE 64a9643ea8Slogwang #define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) 65a9643ea8Slogwang 66a9643ea8Slogwang #define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) 67a9643ea8Slogwang #define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) 68a9643ea8Slogwang #endif 69a9643ea8Slogwang 70a9643ea8Slogwang /* 71a9643ea8Slogwang * Option bits for the third argument of wait4. WNOHANG causes the 72a9643ea8Slogwang * wait to not hang if there are no stopped or terminated processes, rather 73a9643ea8Slogwang * returning an error indication in this case (pid==0). WUNTRACED 74a9643ea8Slogwang * indicates that the caller should receive status about untraced children 75a9643ea8Slogwang * which stop due to signals. If children are stopped and a wait without 76a9643ea8Slogwang * this option is done, it is as though they were still running... nothing 77a9643ea8Slogwang * about them is returned. WNOWAIT only request information about zombie, 78a9643ea8Slogwang * leaving the proc around, available for later waits. 79a9643ea8Slogwang */ 80a9643ea8Slogwang #define WNOHANG 1 /* Don't hang in wait. */ 81a9643ea8Slogwang #define WUNTRACED 2 /* Tell about stopped, untraced children. */ 82a9643ea8Slogwang #define WSTOPPED WUNTRACED /* SUS compatibility */ 83a9643ea8Slogwang #define WCONTINUED 4 /* Report a job control continued process. */ 84a9643ea8Slogwang #define WNOWAIT 8 /* Poll only. Don't delete the proc entry. */ 85a9643ea8Slogwang #define WEXITED 16 /* Wait for exited processes. */ 86a9643ea8Slogwang #define WTRAPPED 32 /* Wait for a process to hit a trap or 87a9643ea8Slogwang a breakpoint. */ 88a9643ea8Slogwang 89a9643ea8Slogwang #if __BSD_VISIBLE 90a9643ea8Slogwang #define WLINUXCLONE 0x80000000 /* Wait for kthread spawned from linux_clone. */ 91a9643ea8Slogwang #endif 92a9643ea8Slogwang 93a9643ea8Slogwang #ifndef _IDTYPE_T_DECLARED 94a9643ea8Slogwang typedef enum 95a9643ea8Slogwang #if __BSD_VISIBLE 96a9643ea8Slogwang idtype /* pollutes XPG4.2 namespace */ 97a9643ea8Slogwang #endif 98a9643ea8Slogwang { 99a9643ea8Slogwang /* 100a9643ea8Slogwang * These names were mostly lifted from Solaris source code and 101a9643ea8Slogwang * still use Solaris style naming to avoid breaking any 102a9643ea8Slogwang * OpenSolaris code which has been ported to FreeBSD. There 103a9643ea8Slogwang * is no clear FreeBSD counterpart for all of the names, but 104a9643ea8Slogwang * some have a clear correspondence to FreeBSD entities. 105a9643ea8Slogwang * 106a9643ea8Slogwang * The numerical values are kept synchronized with the Solaris 107a9643ea8Slogwang * values. 108a9643ea8Slogwang */ 109a9643ea8Slogwang P_PID, /* A process identifier. */ 110a9643ea8Slogwang P_PPID, /* A parent process identifier. */ 111a9643ea8Slogwang P_PGID, /* A process group identifier. */ 112a9643ea8Slogwang P_SID, /* A session identifier. */ 113a9643ea8Slogwang P_CID, /* A scheduling class identifier. */ 114a9643ea8Slogwang P_UID, /* A user identifier. */ 115a9643ea8Slogwang P_GID, /* A group identifier. */ 116a9643ea8Slogwang P_ALL, /* All processes. */ 117a9643ea8Slogwang P_LWPID, /* An LWP identifier. */ 118a9643ea8Slogwang P_TASKID, /* A task identifier. */ 119a9643ea8Slogwang P_PROJID, /* A project identifier. */ 120a9643ea8Slogwang P_POOLID, /* A pool identifier. */ 121a9643ea8Slogwang P_JAILID, /* A zone identifier. */ 122a9643ea8Slogwang P_CTID, /* A (process) contract identifier. */ 123a9643ea8Slogwang P_CPUID, /* CPU identifier. */ 124a9643ea8Slogwang P_PSETID /* Processor set identifier. */ 125a9643ea8Slogwang } idtype_t; /* The type of id_t we are using. */ 126a9643ea8Slogwang 127a9643ea8Slogwang #if __BSD_VISIBLE 128a9643ea8Slogwang #define P_ZONEID P_JAILID 129a9643ea8Slogwang #endif 130a9643ea8Slogwang #define _IDTYPE_T_DECLARED 131a9643ea8Slogwang #endif 132a9643ea8Slogwang 133a9643ea8Slogwang /* 134a9643ea8Slogwang * Tokens for special values of the "pid" parameter to wait4. 135a9643ea8Slogwang * Extended struct __wrusage to collect rusage for both the target 136a9643ea8Slogwang * process and its children within one wait6() call. 137a9643ea8Slogwang */ 138a9643ea8Slogwang #if __BSD_VISIBLE 139a9643ea8Slogwang #define WAIT_ANY (-1) /* any process */ 140a9643ea8Slogwang #define WAIT_MYPGRP 0 /* any process in my process group */ 141a9643ea8Slogwang #endif /* __BSD_VISIBLE */ 142a9643ea8Slogwang 143a9643ea8Slogwang #if defined(_KERNEL) || defined(_WANT_KW_EXITCODE) 144a9643ea8Slogwang 145a9643ea8Slogwang /* 146a9643ea8Slogwang * Clamp the return code to the low 8 bits from full 32 bit value. 147a9643ea8Slogwang * Should be used in kernel to construct the wait(2)-compatible process 148a9643ea8Slogwang * status to usermode. 149a9643ea8Slogwang */ 150a9643ea8Slogwang #define KW_EXITCODE(ret, sig) W_EXITCODE((ret) & 0xff, (sig)) 151a9643ea8Slogwang 152a9643ea8Slogwang #endif /* _KERNEL || _WANT_KW_EXITCODE */ 153a9643ea8Slogwang 154a9643ea8Slogwang #ifndef _KERNEL 155a9643ea8Slogwang 156a9643ea8Slogwang #include <sys/types.h> 157a9643ea8Slogwang 158a9643ea8Slogwang __BEGIN_DECLS 159a9643ea8Slogwang struct __siginfo; 160a9643ea8Slogwang pid_t wait(int *); 161a9643ea8Slogwang pid_t waitpid(pid_t, int *, int); 162a9643ea8Slogwang #if __POSIX_VISIBLE >= 200112 163a9643ea8Slogwang int waitid(idtype_t, id_t, struct __siginfo *, int); 164a9643ea8Slogwang #endif 165a9643ea8Slogwang #if __BSD_VISIBLE 166a9643ea8Slogwang struct rusage; 167a9643ea8Slogwang struct __wrusage; 168a9643ea8Slogwang pid_t wait3(int *, int, struct rusage *); 169a9643ea8Slogwang pid_t wait4(pid_t, int *, int, struct rusage *); 170a9643ea8Slogwang pid_t wait6(idtype_t, id_t, int *, int, struct __wrusage *, 171a9643ea8Slogwang struct __siginfo *); 172a9643ea8Slogwang #endif 173a9643ea8Slogwang __END_DECLS 174a9643ea8Slogwang #endif /* !_KERNEL */ 175a9643ea8Slogwang 176a9643ea8Slogwang #endif /* !_SYS_WAIT_H_ */ 177