Annotation of researchv10no/cmd/renice.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <errno.h>
        !             3: #include <sys/pioctl.h>
        !             4: #include <sys/param.h>
        !             5: #include <sys/types.h>
        !             6: #include <sys/vtimes.h>
        !             7: #include <sys/proc.h>
        !             8: 
        !             9: extern int errno;
        !            10: 
        !            11: char *progname, procname[16]; struct proc p; int nerrors;
        !            12: 
        !            13: main(argc, argv)
        !            14: char **argv;
        !            15: {
        !            16:        int fd, pri = NZERO-1, dpri;
        !            17:        progname = *argv;
        !            18:        if (argv[1]) {
        !            19:                if (argv[1][0] == '-')
        !            20:                        pri = atoi(*++argv+1);
        !            21:        } else
        !            22:                error();
        !            23:        while (*++argv) {
        !            24:                sprintf(procname, "/proc/%05d", atoi(*argv));
        !            25:                if ((fd = open(procname, 0)) < 0 ||
        !            26:                    ioctl(fd, PIOCGETPR, &p) < 0 ||
        !            27:                    (dpri = pri + NZERO - p.p_nice,
        !            28:                    ioctl(fd, PIOCNICE, &dpri)) < 0)
        !            29:                        error();
        !            30:                close(fd);
        !            31:        }
        !            32:        exit(nerrors != 0);
        !            33: }
        !            34: 
        !            35: error()
        !            36: {
        !            37:        switch (errno) {
        !            38:        case 0:
        !            39:                fprintf(stderr, "usage: %s [ -pri ] pid ...\n", progname); break;
        !            40:        case EACCES:
        !            41:        case EPERM:
        !            42:                fprintf(stderr, "%s: no permission\n", procname); break;
        !            43:        case ENOENT:
        !            44:                fprintf(stderr, "%s: no such process\n", procname); break;
        !            45:        default:
        !            46:                fprintf(stderr, "%s: unexpected error %d\n", procname, errno);
        !            47:        }
        !            48:        ++nerrors;
        !            49: }

unix.superglobalmegacorp.com

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