home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / byte-benchmarks3.1 / part01 / src / spawn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-01  |  1.7 KB  |  77 lines

  1. /*******************************************************************************
  2.  *  The BYTE UNIX Benchmarks - Release 3
  3.  *          Module: spawn.c   SID: 3.3 5/15/91 19:30:20
  4.  *          
  5.  *******************************************************************************
  6.  * Bug reports, patches, comments, suggestions should be sent to:
  7.  *
  8.  *    Ben Smith, Rick Grehan or Tom Yagerat BYTE Magazine
  9.  *    ben@bytepb.byte.com   rick_g@bytepb.byte.com   tyager@bytepb.byte.com
  10.  *
  11.  *******************************************************************************
  12.  *  Modification Log:
  13.  *  $Header: spawn.c,v 3.4 87/06/22 14:32:48 kjmcdonell Beta $
  14.  *  August 29, 1990 - Modified timing routines (ty)
  15.  *
  16.  ******************************************************************************/
  17. char SCCSid[] = "@(#) @(#)spawn.c:3.3 -- 5/15/91 19:30:20";
  18. /*
  19.  *  Process creation
  20.  *
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include "timeit.c"
  25.  
  26. unsigned long iter;
  27.  
  28. report()
  29. {
  30.     fprintf(stderr,"%ld loops\n", iter);
  31.     exit(0);
  32. }
  33.  
  34. main(argc, argv)
  35. int    argc;
  36. char    *argv[];
  37. {
  38.     int    slave, count, count1, duration;
  39.     int    status;
  40.  
  41.     if (argc != 2) {
  42.         printf("Usage: %s duration \n", argv[0]);
  43.         exit(1);
  44.     }
  45.  
  46.     duration = atoi(argv[1]);
  47.  
  48.     iter = 0;
  49.     wake_me(duration, report);
  50.  
  51.     while (1) {
  52.         if ((slave = fork()) == 0) {
  53.             /* slave .. boring */
  54. #if debug
  55.             printf("fork OK\n");
  56. #endif
  57.             /* kill it right away */
  58.             exit(0);
  59.         } else if (slave < 0) {
  60.             /* woops ... */
  61.             printf("Fork failed at iteration %d\n", iter);
  62.             perror("Reason");
  63.             exit(2);
  64.         } else
  65.             /* master */
  66.             wait(&status);
  67.         if (status != 0) {
  68.             printf("Bad wait status: 0x%x\n", status);
  69.             exit(2);
  70.         }
  71.         iter++;
  72. #if debug
  73.         printf("Child %d done.\n", slave);
  74. #endif
  75.         }
  76. }
  77.