home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / sys / wait.h < prev   
C/C++ Source or Header  |  1993-10-19  |  7KB  |  219 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  */
  7. /*
  8.  * HISTORY
  9.  *  7-Jan-93  Mac Gillon (mgillon) at NeXT
  10.  *    Integrated POSIX support
  11.  *
  12.  * 29-Apr-92  Peter King (king) at NeXT
  13.  *    Made wait stucture layout be dependant on __BIG_ENDIAN__
  14.  *    __LITTLE_ENDIAN__ predefines.
  15.  *
  16.  * 27-Sep-89  Morris Meyer (mmeyer) at NeXT
  17.  *    NFS 4.0 Changes: define arguments to wait4() system call.
  18.  *
  19.  * 06-Jan-88  Jay Kistler (jjk) at Carnegie Mellon University
  20.  *    Made file reentrant.  Added declarations for __STDC__.
  21.  *
  22.  * 14-Dec-86  Avadis Tevanian (avie) at Carnegie-Mellon University
  23.  *    Merged romp and 68000 definitions since they were the same.
  24.  *    The real conditional should be dependent on byte ordering.
  25.  *
  26.  * 30-May-86  Jonathan J. Chew (jjc) at Carnegie-Mellon University
  27.  *    Added 68000 dependent definitions of w_t and w_S very similar to
  28.  *    those for the ROMP.
  29.  *
  30.  * 19-Feb-86  Bill Bolosky (bolosky) at Carnegie-Mellon University
  31.  *    Added alternate definitions of w_T and w_S for Sailboat under
  32.  *    switch ROMP.
  33.  */
  34.  
  35. /*
  36.  * Copyright (c) 1982, 1986 Regents of the University of California.
  37.  * All rights reserved.  The Berkeley software License Agreement
  38.  * specifies the terms and conditions for redistribution.
  39.  *
  40.  *    @(#)wait.h    7.1 (Berkeley) 6/4/86
  41.  */
  42.  
  43. #ifndef    _WAIT_
  44. #define    _WAIT_    1
  45.  
  46. #if    !defined(KERNEL)
  47.     #include <standards.h>
  48. #endif    /* POSIX_KERN */
  49.  
  50. /*
  51.  * This file holds definitions relevent to the wait system call.
  52.  * Some of the options here are available only through the ``wait3''
  53.  * entry point; the old entry point with one argument has more fixed
  54.  * semantics, never returning status of unstopped children, hanging until
  55.  * a process terminates if any are outstanding, and never returns
  56.  * detailed information about process resource utilization (<vtimes.h>).
  57.  */
  58.  
  59. #if     defined(_POSIX_SOURCE) && !defined(KERNEL)
  60.     #include <sys/types.h>
  61.  
  62.     #ifdef __STDC__
  63.         extern pid_t wait(int *stat_loc);
  64.         extern pid_t waitpid(pid_t pid, int *stat_loc,
  65.             int options);
  66.     #else
  67.         extern pid_t wait();
  68.         extern pid_t waitpid();
  69.     #endif /* __STDC__ */
  70.  
  71.     #define WNOHANG        01    /* dont hang in wait */
  72.     #define WUNTRACED    02    /* tell about stopped, */
  73.                     /* untraced children */
  74.  
  75.     /*
  76.      * Macros to interpret the argument returned by wait() and
  77.      * waitpid().
  78.      */
  79.  
  80.     /* Evaluates to nonzero if and only if status indicates
  81.      * stopped child.
  82.      */
  83.     #define WIFSTOPPED(status)    ((status) & 0100)
  84.  
  85.     /* If WIFSTOPPED(status) is true, then this macro evaluates
  86.      * to the number of the signal that caused the child to stop.
  87.      * Otherwise, it evaluates to -1.
  88.      */
  89.     #define WSTOPSIG(status)    (int)(WIFSTOPPED(status) ? \
  90.                       (((status) >> 8) & 0177) : -1)
  91.  
  92.     /* Evaluates to nonzero if and only if status indicates
  93.      * the child terminated normally.
  94.      */
  95.     #define WIFEXITED(status)    (!((status) & 0377))
  96.  
  97.     /* If WIFEXITED(status) is true, then this macro evaluates
  98.      * to the lower order 8 bits of the child's exit status.
  99.      * Otherwise, it evaluates to -1.
  100.      */
  101.     #define WEXITSTATUS(status)    (int)(WIFEXITED(status) ? \
  102.                           (((status) >> 8) & 0377) : -1)
  103.  
  104.     /* Evaluates to nonzero if and only if status indicates
  105.      * the child terminated abnormally.
  106.      */
  107.     #define WIFSIGNALED(status)    ( !WIFEXITED(status) && \
  108.                       !WIFSTOPPED(status) )
  109.  
  110.     /* If WIFSIGNALED(status) is true, then this macro evaluates
  111.      * to the number of the signal that terminated the child.
  112.      * Otherwise, it evaluates to -1.
  113.      */
  114.     #define WTERMSIG(status)    (int)(WIFSIGNALED(status) ? \
  115.                       ((status) & 0177) : -1)
  116.  
  117. #endif     /* _POSIX_SOURCE  && !KERNEL */
  118.  
  119. #if    defined(_NEXT_SOURCE) 
  120. /*
  121.  * Structure of the information in the first word returned by both
  122.  * wait and wait3.  If w_stopval==WSTOPPED, then the second structure
  123.  * describes the information returned, else the first.  See WUNTRACED below.
  124.  */
  125. union wait    {
  126.     int    w_status;        /* used in syscall */
  127.     /*
  128.      * Terminated process status.
  129.      */
  130.     struct {
  131. #if    __BIG_ENDIAN__
  132.         unsigned short  w_PAD16;
  133.         unsigned        w_Retcode:8;    /* exit code if w_termsig==0 */
  134.          unsigned        w_Coredump:1;   /* core dump indicator */
  135.          unsigned        w_Termsig:7;    /* termination signal */
  136. #else    __BIG_ENDIAN__
  137.         unsigned short    w_Termsig:7;    /* termination signal */
  138.         unsigned short    w_Coredump:1;    /* core dump indicator */
  139.         unsigned short    w_Retcode:8;    /* exit code if w_termsig==0 */
  140. #endif    __BIG_ENDIAN__
  141.     } w_T;
  142.     /*
  143.      * Stopped process status.  Returned
  144.      * only for traced children unless requested
  145.      * with the WUNTRACED option bit.
  146.      */
  147.     struct {
  148. #if    __BIG_ENDIAN__
  149.         unsigned short  w_PAD16;
  150.          unsigned        w_Stopsig:8;    /* signal that stopped us */
  151.          unsigned        w_Stopval:8;    /* == W_STOPPED if stopped */
  152. #else    __BIG_ENDIAN__
  153.         unsigned short    w_Stopval:8;    /* == W_STOPPED if stopped */
  154.         unsigned short    w_Stopsig:8;    /* signal that stopped us */
  155. #endif    __BIG_ENDIAN__
  156.     } w_S;
  157. };
  158. #define    w_termsig    w_T.w_Termsig
  159. #define w_coredump    w_T.w_Coredump
  160. #define w_retcode    w_T.w_Retcode
  161. #define w_stopval    w_S.w_Stopval
  162. #define w_stopsig    w_S.w_Stopsig
  163.  
  164.  
  165. #define    WSTOPPED    0177    /* value of s.stopval if process is stopped */
  166.  
  167. #if    !defined(_POSIX_SOURCE) || POSIX_KERN
  168.  
  169.     /*
  170.      * Option bits for the second argument of wait3.  WNOHANG causes the
  171.      * wait to not hang if there are no stopped or terminated processes, 
  172.      * rather returning an error indication in this case (pid==0).  
  173.      * WUNTRACED indicates that the caller should receive status about
  174.      * untraced children which stop due to signals.  If children are
  175.      * stopped and a wait without this option is done, it is as though
  176.      * they were still running... nothing about them is returned.
  177.      */
  178. #define WNOHANG        1    /* dont hang in wait */
  179. #define WUNTRACED    2    /* tell about stopped, untraced children */
  180.  
  181. #define WIFSTOPPED(x)    ((x).w_stopval == WSTOPPED)
  182. #define WIFSIGNALED(x)    ((x).w_stopval != WSTOPPED && (x).w_termsig != 0)
  183. #define WIFEXITED(x)    ((x).w_stopval != WSTOPPED && (x).w_termsig == 0)
  184.  
  185. #if    defined(__STDC__) && !defined(KERNEL)
  186.     #import <sys/resource.h>
  187.     extern int wait(union wait *);
  188. #endif    /* __STDC__ && ! KERNEL*/
  189.  
  190. #endif    /* !_POSIX_SOURCE  || POSIX_KERN */
  191.  
  192. #ifndef KERNEL
  193.     #import <sys/resource.h>
  194.  
  195.     #ifdef __STDC__
  196.         extern int wait3(union wait *, int,
  197.             struct rusage *);
  198.     #else
  199.         extern int wait3();
  200.     #endif /* __STDC__ */    
  201. #endif /* !KERNEL */
  202. #endif /* _NEXT_SOURCE */
  203.  
  204. /* SUN_VFS */
  205. #ifdef    KERNEL
  206.     /* 
  207.      * Arguments to wait4() system call, included here so it may
  208.      * be called by other routines in the kernel 
  209.      */
  210.     struct wait4_args {
  211.         int pid;
  212.         union wait *status;
  213.         int options;
  214.         struct rusage *rusage;
  215.     };
  216. #endif KERNEL
  217. /* end SUN_VFS */
  218. #endif    _WAIT_
  219.