home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d2xx / d282 / rcs.lha / RCS / rcs.zoo / rcs / rsbx.lib / waitchild.c < prev    next >
C/C++ Source or Header  |  1989-11-04  |  3KB  |  98 lines

  1. /****** rsbx.lib/WaitChild() *************************************************
  2. *
  3. *   NAME
  4. *    WaitChild -- Wait for child process to terminate.
  5. *
  6. *   SYNOPSIS
  7. *    term = WaitChild(child, status)
  8. *
  9. *    struct ChildNode *WaitChild(struct ChildNode *, long * );
  10. *
  11. *   FUNCTION
  12. *    This function waits for a child process to terminate, and places the
  13. *        child's return val in the long pointed to by status. If the child
  14. *        identifier provided doen't belong to a child of this process, then
  15. *        0 is returned. If the child identifier is zero, returns the child
  16. *        identifier of a child that has terminated and sets the long status
  17. *        points to to its return val. If the child identifier is zero and
  18. *        no child has yet terminated, wait for any child to terminate and
  19. *        return its identifier and set the long status points to to its
  20. *        return val. If the child identifier is zero and there are no child
  21. *        processes of this process, return zero.
  22. *
  23. *   INPUTS
  24. *    child         - Child identifier as returned by LaunchChildl() or by
  25. *                    LaunchChildv().
  26. *    status        - Pointer to a long to store the return val of the child
  27. *                    in.
  28. *
  29. *   RESULT
  30. *    term          - Child identifier of the child process whos return val
  31. *                    was stored in the long pointed to by status, or zero
  32. *                    if there was an error.
  33. *
  34. *   NOTES
  35. *
  36. *   SEE ALSO
  37. *    ChildStatus(), CreateFamily(), EmptyMorgue(), LaunchChildl(),
  38. *    LaunchChildv(), OrphanChild(), OrphanChildren().
  39. *
  40. *   BUGS
  41. *    None Known.
  42. *
  43. ******************************************************************************
  44. *
  45. */
  46.  
  47. #include <proto/exec.h>
  48. #include <rsbx/ChildTasking.h>
  49.  
  50.  
  51. struct ChildNode *WaitChild(struct ChildNode *child, long *status)
  52.     {
  53.     struct ChildNode *node;
  54.  
  55.     while (1)
  56.         {
  57.         EmptyMorgue();
  58.  
  59.         if (child)
  60.             {
  61.             for (node = (struct ChildNode *)_Children->ChildList.mlh_Head;
  62.                 node->node.mln_Succ;
  63.                 node = (struct ChildNode *)node->node.mln_Succ)
  64.                 {
  65.                 if (node == child)
  66.                     {
  67.                     if (!child->notice.noticeptr)
  68.                         {
  69.                         *status = child->notice.ret;
  70.                         return child;
  71.                         }
  72.                     break;
  73.                     }
  74.                 }
  75.             if (!node->node.mln_Succ)
  76.                 {
  77.                 return 0;
  78.                 }
  79.             }
  80.         else
  81.             {
  82.             for (node = (struct ChildNode *)_Children->ChildList.mlh_Head;
  83.                 node->node.mln_Succ;
  84.                 node = (struct ChildNode *)node->node.mln_Succ)
  85.                 {
  86.                 if (!node->notice.noticeptr)
  87.                     {
  88.                     *status = node->notice.ret;
  89.                     return node;
  90.                     }
  91.                 }
  92.  
  93.             }
  94.  
  95.         WaitPort(_Children->Morgue);
  96.         }
  97.     }
  98.