home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / sas_unix_lib.lha / unix / src / wait4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-15  |  1.1 KB  |  58 lines

  1. #include "amiga.h"
  2. #include "signals.h"
  3. #include "processes.h"
  4. #include <sys/wait.h>
  5.  
  6. int wait4(int pid, int *statusp, int options, struct rusage *rusage)
  7. {
  8.   struct process *p;
  9.  
  10.   do {
  11.     int seen = FALSE;
  12.  
  13.     scan_processes(p)
  14.       if (pid == 0 || p->pid == pid)
  15.     {
  16.       seen = TRUE;
  17.  
  18.       if (p->status == exited)
  19.         {
  20.           int pid = p->pid;
  21.  
  22.           if (statusp) *statusp = p->rc;
  23.           _free_entry(p);
  24.  
  25.           return pid;
  26.         }
  27.     }
  28.     if (options & WNOHANG) return 0;
  29.     if (!seen)
  30.       {
  31.     errno = ECHILD;
  32.     return -1;
  33.       }
  34.     _handle_signals(_wait_signals(0));
  35.   } while (1);
  36. }
  37.  
  38. int wait3(int *statusp, int options, struct rusage *rusage)
  39. {
  40.   return wait4(0, statusp, options, rusage);
  41. }
  42.  
  43. int wait(int *statusp)
  44. {
  45.   return wait4(0, statusp, 0, NULL);
  46. }
  47.  
  48. int waitpid(int pid, int *statusp, int options)
  49. {
  50.   /* We have no process groups, so : 
  51.        Our process group encompasses all our children
  52.        Each child is a process group unto itself
  53.      This is somewhat contradictory ... Should this be changed ? */
  54.   if (pid == -1) pid = 0;
  55.   if (pid < 0) pid = -pid;
  56.   return wait4(pid, statusp, options, NULL);
  57. }
  58.