home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_src_sys_c_child < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-09  |  1.1 KB  |  44 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/sys/c/RCS/child,v $
  4.  * $Date: 1996/05/06 09:03:14 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: child,v $
  10.  * Revision 1.1  1996/05/06 09:03:14  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: child,v 1.1 1996/05/06 09:03:14 unixlib Rel $";
  16.  
  17. #include <sys/unix.h>
  18. #include <sys/wait.h>
  19.  
  20. /* This is a utility function used by fork and vfork. It
  21.    searches through the number of children this process
  22.    can have and returns an index to a child suitable for
  23.    re-birth.
  24.  
  25.    A child applicable for re-birth could either be one that
  26.    has terminated or one that was never born in the first
  27.    place.
  28.  
  29.    An unborn child will have no memory allocated to it.  */
  30.  
  31. int
  32. __find_free_child (void)
  33. {
  34.   int i;
  35.  
  36.   for (i = 0; i < CHILD_MAX; i++)
  37.     {
  38.       /* A terminated child will be anything that hasn't stopped.  */
  39.       if (!__u->child[i].status.stopped)
  40.     return i;
  41.     }
  42.   return -1;
  43. }
  44.