1 /*******************************************************************************
2  *  The BYTE UNIX Benchmarks - Release 3
3  *          Module: syscall.c   SID: 3.3 5/15/91 19:30:21
4  *
5  *******************************************************************************
6  * Bug reports, patches, comments, suggestions should be sent to:
7  *
8  *	Ben Smith, Rick Grehan or Tom Yager at BYTE Magazine
9  *	ben@bytepb.byte.com   rick_g@bytepb.byte.com   tyager@bytepb.byte.com
10  *
11  *******************************************************************************
12  *  Modification Log:
13  *  $Header: syscall.c,v 3.4 87/06/22 14:32:54 kjmcdonell Beta $
14  *  August 29, 1990 - Modified timing routines
15  *  October 22, 1997 - code cleanup to remove ANSI C compiler warnings
16  *                     Andy Kahn <kahn@zk3.dec.com>
17  *
18  ******************************************************************************/
19 /*
20  *  syscall  -- sit in a loop calling the system
21  *
22  */
23 char SCCSid[] = "@(#) @(#)syscall.c:3.3 -- 5/15/91 19:30:21";
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #include <sys/wait.h>
31 #include <sys/syscall.h>
32 #include "timeit.c"
33 
34 unsigned long iter;
35 
report()36 void report()
37 {
38 	fprintf(stderr,"COUNT|%ld|1|lps\n", iter);
39 	exit(0);
40 }
41 
main(argc,argv)42 int main(argc, argv)
43 int	argc;
44 char	*argv[];
45 {
46         char   *test;
47 	int	duration;
48 
49 	if (argc < 2) {
50 		fprintf(stderr,"Usage: %s duration [ test ]\n", argv[0]);
51                 fprintf(stderr,"test is one of:\n");
52                 fprintf(stderr,"  \"mix\" (default), \"close\", \"getpid\", \"exec\"\n");
53 		exit(1);
54 	}
55         if (argc > 2)
56             test = argv[2];
57         else
58             test = "mix";
59 
60 	duration = atoi(argv[1]);
61 
62 	iter = 0;
63 	wake_me(duration, report);
64 
65         switch (test[0]) {
66         case 'm':
67 	   while (1) {
68 		close(dup(0));
69 		syscall(SYS_getpid);
70 		getuid();
71 		umask(022);
72 		iter++;
73 	   }
74 	   /* NOTREACHED */
75         case 'c':
76            while (1) {
77                 close(dup(0));
78                 iter++;
79            }
80            /* NOTREACHED */
81         case 'g':
82            while (1) {
83                 syscall(SYS_getpid);
84                 iter++;
85            }
86            /* NOTREACHED */
87         case 'e':
88            while (1) {
89                 pid_t pid = fork();
90                 if (pid < 0) {
91                     fprintf(stderr,"%s: fork failed\n", argv[0]);
92                     exit(1);
93                 } else if (pid == 0) {
94                     execl("/bin/true", "/bin/true", (char *) 0);
95                     fprintf(stderr,"%s: exec /bin/true failed\n", argv[0]);
96                     exit(1);
97                 } else {
98                     if (waitpid(pid, NULL, 0) < 0) {
99                         fprintf(stderr,"%s: waitpid failed\n", argv[0]);
100                         exit(1);
101                     }
102                 }
103                 iter++;
104            }
105            /* NOTREACHED */
106         }
107 
108         exit(9);
109 }
110 
111