summaryrefslogtreecommitdiff
path: root/benchmarks/forks.c
diff options
context:
space:
mode:
authorMichael I. Bushnell <mib@gnu.org>1994-06-24 17:47:16 +0000
committerMichael I. Bushnell <mib@gnu.org>1994-06-24 17:47:16 +0000
commit5200a6c79d4ab0e12eeb6c39076318d7547c7fcb (patch)
tree0470e04f4d6592fef1b7382abdfce4db4e76d287 /benchmarks/forks.c
parentafc483de4510881fffd93f5e3de1b17f92623c91 (diff)
Initial revision
Diffstat (limited to 'benchmarks/forks.c')
-rw-r--r--benchmarks/forks.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/benchmarks/forks.c b/benchmarks/forks.c
new file mode 100644
index 00000000..ae9efaab
--- /dev/null
+++ b/benchmarks/forks.c
@@ -0,0 +1,51 @@
+/* From 4.4 BSD sys/tests/benchmarks/forks.c. */
+
+/*
+ * Benchmark program to calculate fork+wait
+ * overhead (approximately). Process
+ * forks and exits while parent waits.
+ * The time to run this program is used
+ * in calculating exec overhead.
+ */
+
+main(argc, argv)
+ char *argv[];
+{
+ register int nforks, i;
+ char *cp;
+ int pid, child, status, brksize;
+
+ if (argc < 2) {
+ printf("usage: %s number-of-forks sbrk-size\n", argv[0]);
+ exit(1);
+ }
+ nforks = atoi(argv[1]);
+ if (nforks < 0) {
+ printf("%s: bad number of forks\n", argv[1]);
+ exit(2);
+ }
+ brksize = atoi(argv[2]);
+ if (brksize < 0) {
+ printf("%s: bad size to sbrk\n", argv[2]);
+ exit(3);
+ }
+ cp = (char *)sbrk(brksize);
+ if ((int)cp == -1) {
+ perror("sbrk");
+ exit(4);
+ }
+ for (i = 0; i < brksize; i += 1024)
+ cp[i] = i;
+ while (nforks-- > 0) {
+ child = fork();
+ if (child == -1) {
+ perror("fork");
+ exit(-1);
+ }
+ if (child == 0)
+ _exit(-1);
+ while ((pid = wait(&status)) != -1 && pid != child)
+ ;
+ }
+ exit(0);
+}