1 /* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1989 The Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)nice.c 5.5 (Berkeley) 06/18/92"; 16 #endif /* not lint */ 17 18 #include <sys/types.h> 19 #include <sys/time.h> 20 #include <sys/resource.h> 21 22 #include <stdio.h> 23 #include <ctype.h> 24 25 #define DEFNICE 10 26 27 /* ARGSUSED */ 28 main(argc, argv) 29 int argc; 30 char **argv; 31 { 32 extern int errno; 33 int niceness; 34 char *strerror(); 35 36 niceness = DEFNICE; 37 if (argv[1][0] == '-') 38 if (isdigit(argv[1][1])) { 39 niceness = atoi(argv[1] + 1); 40 ++argv; 41 } 42 else { 43 (void)fprintf(stderr, "nice: illegal option -- %c\n", 44 argv[1][1]); 45 usage(); 46 } 47 48 if (!argv[1]) 49 usage(); 50 51 errno = 0; 52 niceness += getpriority(PRIO_PROCESS, 0); 53 if (errno) { 54 (void)fprintf(stderr, "nice: getpriority: %s\n", 55 strerror(errno)); 56 exit(1); 57 } 58 if (setpriority(PRIO_PROCESS, 0, niceness)) { 59 (void)fprintf(stderr, 60 "nice: setpriority: %s\n", strerror(errno)); 61 exit(1); 62 } 63 execvp(argv[1], &argv[1]); 64 (void)fprintf(stderr, 65 "nice: %s: %s\n", argv[1], strerror(errno)); 66 exit(1); 67 } 68 69 usage() 70 { 71 (void)fprintf(stderr, 72 "nice [ -# ] command [ options ] [ operands ]\n"); 73 exit(1); 74 } 75