home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / jove-4.16-src.tgz / tar.out / bsd / jove / sysprocs.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  4KB  |  121 lines

  1. /************************************************************************
  2.  * This program is Copyright (C) 1986-1996 by Jonathan Payne.  JOVE is  *
  3.  * provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is *
  5.  * included in all the files.                                           *
  6.  ************************************************************************/
  7.  
  8. /* The diversity of process management is complicated and difficult to handle.
  9.  * - In some systems (noteably POSIX), a process id has type "pid_t"
  10.  * - V7 only has wait.  POSIX has waitpid (with options).  BSD has
  11.  *   wait3.  Someone has wait2.
  12.  * - The status result set by wait and used by WIF* has type
  13.  *   "union wait" in BSD, but "int" everywhere else.
  14.  * - The WIF* functions are defined in <sys/wait.h> by BSD and POSIX.
  15.  * - WTERMSIG seems to be a creation of POSIX
  16.  * - Some systems have vfork(1) and perform better if it is used
  17.  *   in place of fork(1).
  18.  *
  19.  * This header attempts to span this diversity.  We provide:
  20.  * - POSIX pid_t
  21.  * - wait_opt, to accept options (and use them, if possible).
  22.  * - wait_status_t
  23.  * - WIF*
  24.  * - WTERMSIG
  25.  */
  26.  
  27. #ifdef POSIX_PROCS
  28.  
  29. # include <sys/types.h>    /* defines pid_t */
  30. # include <sys/wait.h>
  31.   typedef int    wait_status_t;
  32. # define wait_opt(stat_loc, options)    waitpid(-1, stat_loc, options)
  33.  
  34. #else /*!POSIX_PROCS*/
  35.  
  36. #ifndef __amigaos__
  37.  typedef int    pid_t;
  38. #endif
  39.  
  40. # ifdef BSD_WAIT
  41.  
  42. #  include <sys/wait.h>
  43.  
  44.   typedef union wait    wait_status_t;
  45.  
  46. #  ifndef WEXITSTATUS
  47. #   define WEXITSTATUS(w)    ((w).w_retcode)
  48. #  endif
  49.  
  50. #  ifndef WTERMSIG
  51. #   define WTERMSIG(w)    ((w).w_termsig)
  52. #  endif
  53.  
  54. #  ifndef WAIT3
  55. #   define wait_opt(stat_loc, options)    wait2(stat_loc, options)
  56. #  else
  57. #   define wait_opt(stat_loc, options)    wait3(stat_loc, options, (struct rusage *)NULL)
  58. #  endif
  59.  
  60. # else /*!BSD_WAIT*/
  61.  
  62.   typedef int    wait_status_t;
  63.  
  64. #  ifdef UNIX
  65.  
  66. #   define WIFSTOPPED(w)    ((w & 0377) == 0177)
  67. #   define WIFEXITED(w)    ((w & 0377) == 0)
  68. #   define WIFSIGNALED(w)    (((w >> 8) & 0377) == 0)
  69. #   define WEXITSTATUS(w)    ((w >> 8) & 0377)
  70. #   define WTERMSIG(w)    (w & 0177)
  71.  
  72. #   define wait_opt(stat_loc, options)        wait(stat_loc)
  73.  
  74. #  endif /* UNIX */
  75.  
  76. # endif /*!BSD_WAIT*/
  77. #endif /*!POSIX_PROCS*/
  78.  
  79. #ifndef FULL_UNISTD
  80. # ifndef POSIX_UNISTD
  81.  
  82. /* ??? pid_t may be changed by default argument promotions.
  83.  * If so, this prototype might be wrong.
  84.  */
  85. extern int    kill proto((pid_t /*pid*/, int /*sig*/));    /* signal.h */
  86.  
  87. extern pid_t    fork proto((void));
  88. extern pid_t    getpid proto((void));
  89. extern int    getuid proto((void));
  90. extern int    setuid proto((int));
  91. # endif /* !POSIX_UNISTD */
  92.  
  93. # ifdef USE_VFORK
  94. extern int    UNMACRO(vfork) proto((void));
  95. # endif
  96. #endif /* !FULL_UNISTD */
  97.  
  98. /* This nest of #ifdefs is simply to define NEWPG() which makes
  99.  * the current process a process group leader of a new process group.
  100.  * ??? pid_t may be changed by default argument promotions.
  101.  * If so, this prototype might be wrong.
  102.  */
  103. #ifdef POSIX_PROCS
  104. # ifndef FULL_UNISTD
  105.    extern int    UNMACRO(setpgid) proto((pid_t /*pid*/, pid_t /*pgid*/));
  106. # endif
  107. # define NEWPG()    setpgid(0, getpid())
  108. #else /* !POSIX_PROCS */
  109. # ifdef BSD_SETPGRP
  110. #  ifndef FULL_UNISTD
  111.    extern int    UNMACRO(setpgrp) proto((pid_t /*pid*/, pid_t /*pgrp*/));
  112. #  endif
  113. #  define NEWPG()    setpgrp(0, getpid())
  114. # else /* !(defined(BSD_SETPGRP) || defined(POSIX_PROCS)) */
  115. #  ifndef FULL_UNISTD
  116.    extern int    UNMACRO(setpgrp) proto((void));
  117. #  endif
  118. #  define NEWPG()    setpgrp()
  119. # endif /* !(defined(BSD_SETPGRP) || defined(POSIX_PROCS)) */
  120. #endif /* !POSIX_PROCS */
  121.