home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / byteunix.lzh / byte.1 / spawn.c < prev    next >
C/C++ Source or Header  |  1990-05-11  |  1KB  |  61 lines

  1. /*******************************************************************************
  2.  *  The BYTE UNIX Benchmarks - Release 2
  3.  *          Module: spawn.c   SID: 2.4 4/17/90 16:45:35
  4.  *          
  5.  *******************************************************************************
  6.  * Bug reports, patches, comments, suggestions should be sent to:
  7.  *
  8.  *    Ben Smith or Rick Grehan at BYTE Magazine
  9.  *    bensmith@bixpb.UUCP    rick_g@bixpb.UUCP
  10.  *
  11.  *******************************************************************************
  12.  *  Modification Log:
  13.  *  $Header: spawn.c,v 3.4 87/06/22 14:32:48 kjmcdonell Beta $
  14.  *
  15.  ******************************************************************************/
  16. char SCCSid[] = "@(#) @(#)spawn.c:2.4 -- 4/17/90 16:45:35";
  17. /*
  18.  *  Process creation
  19.  *
  20.  */
  21.  
  22. main(argc, argv)
  23. int    argc;
  24. char    *argv[];
  25. {
  26.     int    iter;
  27.     int    slave;
  28.     int    status;
  29.  
  30.     if (argc != 2) {
  31.         printf("Usage: %s count\n", argv[0]);
  32.         exit(1);
  33.     }
  34.  
  35.     iter = atoi(argv[1]);
  36.  
  37.     while (iter-- > 0) {
  38.         if ((slave = fork()) == 0) {
  39.             /* slave .. boring */
  40. #if debug
  41.             printf("fork OK\n");
  42. #endif
  43.             exit(0);
  44.         } else if (slave < 0) {
  45.             /* woops ... */
  46.             printf("Fork failed at iteration %d\n", iter);
  47.             perror("Reason");
  48.             exit(2);
  49.         } else
  50.             wait(&status);
  51.         if (status != 0) {
  52.             printf("Bad wait status: 0x%x\n", status);
  53.             exit(2);
  54.         }
  55. #if debug
  56.         printf("Child %d done.\n", slave);
  57. #endif
  58.     }
  59.     exit(0);
  60. }
  61.