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

Defined functions

donice defined in line 79; used 1 times
  • in line 74
main defined in line 26; never used

Defined variables

copyright defined in line 8; never used
sccsid defined in line 12; never used
Last modified: 1996-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 679
Valid CSS Valid XHTML 1.0 Strict