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