1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)renice.c	5.1 (Berkeley) 5/28/85";
  15: #endif not lint
  16: 
  17: #include <sys/time.h>
  18: #include <sys/resource.h>
  19: #include <stdio.h>
  20: #include <pwd.h>
  21: 
  22: /*
  23:  * Change the priority (nice) of processes
  24:  * or groups of processes which are already
  25:  * running.
  26:  */
  27: main(argc, argv)
  28:     char **argv;
  29: {
  30:     int which = PRIO_PROCESS;
  31:     int who = 0, prio, errs = 0;
  32: 
  33:     argc--, argv++;
  34:     if (argc < 2) {
  35:         fprintf(stderr, "usage: renice priority [ [ -p ] pids ] ");
  36:         fprintf(stderr, "[ [ -g ] pgrps ] [ [ -u ] users ]\n");
  37:         exit(1);
  38:     }
  39:     prio = atoi(*argv);
  40:     argc--, argv++;
  41:     if (prio > PRIO_MAX)
  42:         prio = PRIO_MAX;
  43:     if (prio < PRIO_MIN)
  44:         prio = PRIO_MIN;
  45:     for (; argc > 0; argc--, argv++) {
  46:         if (strcmp(*argv, "-g") == 0) {
  47:             which = PRIO_PGRP;
  48:             continue;
  49:         }
  50:         if (strcmp(*argv, "-u") == 0) {
  51:             which = PRIO_USER;
  52:             continue;
  53:         }
  54:         if (strcmp(*argv, "-p") == 0) {
  55:             which = PRIO_PROCESS;
  56:             continue;
  57:         }
  58:         if (which == PRIO_USER) {
  59:             register struct passwd *pwd = getpwnam(*argv);
  60: 
  61:             if (pwd == NULL) {
  62:                 fprintf(stderr, "renice: %s: unknown user\n",
  63:                     *argv);
  64:                 continue;
  65:             }
  66:             who = pwd->pw_uid;
  67:         } else {
  68:             who = atoi(*argv);
  69:             if (who < 0) {
  70:                 fprintf(stderr, "renice: %s: bad value\n",
  71:                     *argv);
  72:                 continue;
  73:             }
  74:         }
  75:         errs += donice(which, who, prio);
  76:     }
  77:     exit(errs != 0);
  78: }
  79: 
  80: donice(which, who, prio)
  81:     int which, who, prio;
  82: {
  83:     int oldprio;
  84:     extern int errno;
  85: 
  86:     errno = 0, oldprio = getpriority(which, who);
  87:     if (oldprio == -1 && errno) {
  88:         fprintf(stderr, "renice: %d: ", who);
  89:         perror("getpriority");
  90:         return (1);
  91:     }
  92:     if (setpriority(which, who, prio) < 0) {
  93:         fprintf(stderr, "renice: %d: ", who);
  94:         perror("setpriority");
  95:         return (1);
  96:     }
  97:     printf("%d: old priority %d, new priority %d\n", who, oldprio, prio);
  98:     return (0);
  99: }

Defined functions

donice defined in line 80; used 1 times
  • in line 75
main defined in line 27; never used

Defined variables

copyright defined in line 8; never used
sccsid defined in line 14; never used
Last modified: 1985-05-29
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1072
Valid CSS Valid XHTML 1.0 Strict