Annotation of Net2/tests/benchmarks/forks.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Benchmark program to calculate fork+wait
                      3:  * overhead (approximately).  Process
                      4:  * forks and exits while parent waits.
                      5:  * The time to run this program is used
                      6:  * in calculating exec overhead.
                      7:  */
                      8: 
                      9: main(argc, argv)
                     10:        char *argv[];
                     11: {
                     12:        register int nforks, i;
                     13:        char *cp;
                     14:        int pid, child, status, brksize;
                     15: 
                     16:        if (argc < 2) {
                     17:                printf("usage: %s number-of-forks sbrk-size\n", argv[0]);
                     18:                exit(1);
                     19:        }
                     20:        nforks = atoi(argv[1]);
                     21:        if (nforks < 0) {
                     22:                printf("%s: bad number of forks\n", argv[1]);
                     23:                exit(2);
                     24:        }
                     25:        brksize = atoi(argv[2]);
                     26:        if (brksize < 0) {
                     27:                printf("%s: bad size to sbrk\n", argv[2]);
                     28:                exit(3);
                     29:        }
                     30:        cp = (char *)sbrk(brksize);
                     31:        if ((int)cp == -1) {
                     32:                perror("sbrk");
                     33:                exit(4);
                     34:        }
                     35:        for (i = 0; i < brksize; i += 1024)
                     36:                cp[i] = i;
                     37:        while (nforks-- > 0) {
                     38:                child = fork();
                     39:                if (child == -1) {
                     40:                        perror("fork");
                     41:                        exit(-1);
                     42:                }
                     43:                if (child == 0)
                     44:                        _exit(-1);
                     45:                while ((pid = wait(&status)) != -1 && pid != child)
                     46:                        ;
                     47:        }
                     48:        exit(0);
                     49: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.