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  *  October 22, 1997 - code cleanup to remove ANSI C compiler warnings
16  *                     Andy Kahn <kahn@zk3.dec.com>
17  *
18  ******************************************************************************/
19 char SCCSid[] = "@(#) @(#)spawn.c:3.3 -- 5/15/91 19:30:20";
20 /*
21  *  Process creation
22  *
23  */
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/wait.h>
28 #include "timeit.c"
29 
30 unsigned long iter;
31 
report()32 void report()
33 {
34 	fprintf(stderr,"COUNT|%lu|1|lps\n", iter);
35 	exit(0);
36 }
37 
main(argc,argv)38 int main(argc, argv)
39 int	argc;
40 char	*argv[];
41 {
42 	int	slave, duration;
43 	int	status;
44 
45 	if (argc != 2) {
46 		fprintf(stderr,"Usage: %s duration \n", argv[0]);
47 		exit(1);
48 	}
49 
50 	duration = atoi(argv[1]);
51 
52 	iter = 0;
53 	wake_me(duration, report);
54 
55 	while (1) {
56 		if ((slave = fork()) == 0) {
57 			/* slave .. boring */
58 #if debug
59 			printf("fork OK\n");
60 #endif
61 			/* kill it right away */
62 			exit(0);
63 		} else if (slave < 0) {
64 			/* woops ... */
65 			fprintf(stderr,"Fork failed at iteration %lu\n", iter);
66 			perror("Reason");
67 			exit(2);
68 		} else
69 			/* master */
70 			wait(&status);
71 		if (status != 0) {
72 			fprintf(stderr,"Bad wait status: 0x%x\n", status);
73 			exit(2);
74 		}
75 		iter++;
76 #if debug
77 		printf("Child %d done.\n", slave);
78 #endif
79 		}
80 }
81