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

  1. /*******************************************************************************
  2.  *  The BYTE UNIX Benchmarks - Release 1
  3.  *          Module: looper.c   SID: 1.4 5/15/91 19:30:22
  4.  *          
  5.  *******************************************************************************
  6.  * Bug reports, patches, comments, suggestions should be sent to:
  7.  *
  8.  *    Ben Smith or Tom Yager at BYTE Magazine
  9.  *    ben@bytepb.byte.com   tyager@bytepb.byte.com
  10.  *
  11.  *******************************************************************************
  12.  *  Modification Log:
  13.  *  
  14.  *  February 25, 1991 -- created (Ben S.)
  15.  *
  16.  ******************************************************************************/
  17. char SCCSid[] = "@(#) @(#)looper.c:1.4 -- 5/15/91 19:30:22";
  18. /*
  19.  *  Shell Process creation
  20.  *
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include "timeit.c"
  25.  
  26. unsigned long iter;
  27. char *cmd_argv[28];
  28. int  cmd_argc;
  29.  
  30. report()
  31. {
  32.     fprintf(stderr,"%ld loops\n", iter);
  33.     exit(0);
  34. }
  35.  
  36. main(argc, argv, env)
  37. int    argc;
  38. char    *argv[];
  39. char    *env[];
  40. {
  41. int    slave, count, count1, duration;
  42. int    status;
  43.  
  44. if (argc < 2) 
  45.     {
  46.     printf("Usage: %s duration command [args..]\n", argv[0]);
  47.     printf("  duration in seconds\n");
  48.     exit(1);
  49.     }
  50.  
  51. if((duration = atoi(argv[1])) < 1)
  52.     {
  53.     printf("Usage: %s duration command [arg..]\n", argv[0]);
  54.     printf("  duration in seconds\n");
  55.     exit(1);
  56.     }
  57.  
  58. /* get command  */
  59. cmd_argc=argc-2;
  60. for( count=2;count < argc; ++count)
  61.     cmd_argv[count-2]=argv[count];
  62. #ifdef DEBUG
  63. printf("<<%s>>",cmd_argv[0]);
  64. for(count=1;count < cmd_argc; ++count)
  65.     printf(" <%s>", cmd_argv[count]);
  66. putchar('\n');
  67. exit(0);
  68. #endif
  69.  
  70. iter = 0;
  71. wake_me(duration, report);
  72.  
  73. while (1) 
  74.     {
  75.     if ((slave = fork()) == 0) 
  76.         { /* execute command */
  77.         execvp(cmd_argv[0],cmd_argv);
  78.         exit(0);
  79.         } 
  80.     else if (slave < 0) 
  81.         {
  82.         /* woops ... */
  83.         printf("Fork failed at iteration %d\n", iter);
  84.         perror("Reason");
  85.         exit(2);
  86.         } 
  87.     else
  88.         /* master */
  89.         wait(&status);
  90.     if (status != 0) 
  91.         {
  92.         printf("Bad wait status: 0x%x\n", status);
  93.         exit(2);
  94.         }
  95.     iter++;
  96.     }
  97. }
  98.