os161-1.99
 All Data Structures
wait.h
00001 /*
00002  * Copyright (c) 2003, 2008
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _KERN_WAIT_H_
00031 #define _KERN_WAIT_H_
00032 
00033 /*
00034  * Definitions for wait().
00035  */
00036 
00037 
00038 /* Flags for waitpid() and equivalent. */
00039 #define WNOHANG      1  /* Nonblocking. */
00040 #define WUNTRACED    2  /* Report stopping as well as exiting processes. */
00041 
00042 /* Special "pids" to wait for. */
00043 #define WAIT_ANY     (-1)       /* Any child process. */
00044 #define WAIT_MYPGRP  0          /* Any process in the same process group. */
00045 
00046 /*
00047  * Result encoding.
00048  *
00049  * The lowest two bits say what happened; the rest encodes up to 30
00050  * bits of exit code. Note that the traditional Unix encoding, which
00051  * is different, wastes most of the bits and can only transmit 8 bits
00052  * of exit code...
00053  */
00054 #define _WWHAT(x)  ((x)&3)      /* lower two bits say what happened */
00055 #define _WVAL(x)   ((x)>>2)     /* the rest is the value */
00056 #define _MKWVAL(x) ((x)<<2)     /* encode a value */
00057 
00058 /* Four things can happen... */
00059 #define __WEXITED    0          /* Process exited by calling _exit(). */
00060 #define __WSIGNALED  1          /* Process received a fatal signal. */
00061 #define __WCORED     2          /* Process dumped core on a fatal signal. */
00062 #define __WSTOPPED   3          /* Process stopped (and didn't exit). */
00063 
00064 /* Test macros, used by applications. */
00065 #define WIFEXITED(x)   (_WWHAT(x)==__WEXITED)
00066 #define WIFSIGNALED(x) (_WWHAT(x)==__WSIGNALED || _WWHAT(x)==__WCORED)
00067 #define WIFSTOPPED(x)  (_WWHAT(x)==__WSTOPPED)
00068 #define WEXITSTATUS(x) (_WVAL(x))
00069 #define WTERMSIG(x)    (_WVAL(x))
00070 #define WSTOPSIG(x)    (_WVAL(x))
00071 #define WCOREDUMP(x)   (_WWHAT(x)==__WCORED)
00072 
00073 /* Encoding macros, used by the kernel to generate the wait result. */
00074 #define _MKWAIT_EXIT(x) (_MKWVAL(x)|__WEXITED)
00075 #define _MKWAIT_SIG(x)  (_MKWVAL(x)|__WSIGNALED)
00076 #define _MKWAIT_CORE(x) (_MKWVAL(x)|__WCORED)
00077 #define _MKWAIT_STOP(x) (_MKWVAL(x)|__WSTOPPED)
00078 
00079 #endif /* _KERN_WAIT_H_ */
 All Data Structures