Annotation of Net2/tests/benchmarks/bench-4.1/csw.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Context switching benchmark.
        !             3:  *
        !             4:  * Force system to context switch 2*nsigs
        !             5:  * times by forking and exchanging signals.
        !             6:  * To calculate system overhead for a context
        !             7:  * switch, the signocsw program must be run
        !             8:  * with nsigs.  Overhead is then estimated by
        !             9:  *     t1 = time csw <n>
        !            10:  *     t2 = time signocsw <n>
        !            11:  *     overhead = t1 - 2 * t2;
        !            12:  */
        !            13: #include <signal.h>
        !            14: 
        !            15: int    sigsub();
        !            16: int    otherpid;
        !            17: int    nsigs;
        !            18: 
        !            19: main(argc, argv)
        !            20:        char *argv[];
        !            21: {
        !            22:        int pid;
        !            23: 
        !            24:        if (argc < 2) {
        !            25:                printf("usage: %s nsignals\n", argv[0]);
        !            26:                exit(1);
        !            27:        }
        !            28:        nsigs = atoi(argv[1]);
        !            29:        signal(SIGALRM, sigsub);
        !            30:        otherpid = getpid();
        !            31:        pid = fork();
        !            32:        if (pid != 0) {
        !            33:                otherpid = pid;
        !            34:                kill(otherpid, SIGALRM);
        !            35:        }
        !            36:        for (;;)
        !            37:                pause();
        !            38: }
        !            39: 
        !            40: sigsub()
        !            41: {
        !            42: 
        !            43:        signal(SIGALRM, sigsub);
        !            44:        kill(otherpid, SIGALRM);
        !            45:        if (--nsigs <= 0)
        !            46:                exit(0);
        !            47: }

unix.superglobalmegacorp.com

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