119845Sdist /* 2*66806Sbostic * Copyright (c) 1989, 1993, 1994 362149Sbostic * The Regents of the University of California. All rights reserved. 438087Sbostic * 542755Sbostic * %sccs.include.redist.c% 619845Sdist */ 719845Sdist 812669Ssam #ifndef lint 962149Sbostic static char copyright[] = 10*66806Sbostic "@(#) Copyright (c) 1989, 1993, 1994\n\ 1162149Sbostic The Regents of the University of California. All rights reserved.\n"; 1238087Sbostic #endif /* not lint */ 131059Sbill 1419845Sdist #ifndef lint 15*66806Sbostic static char sccsid[] = "@(#)nice.c 8.2 (Berkeley) 04/16/94"; 1638087Sbostic #endif /* not lint */ 1719845Sdist 1854037Sbostic #include <sys/types.h> 1912669Ssam #include <sys/time.h> 2012669Ssam #include <sys/resource.h> 2154037Sbostic 2257921Sbostic #include <ctype.h> 23*66806Sbostic #include <err.h> 2457921Sbostic #include <errno.h> 2538087Sbostic #include <stdio.h> 2657921Sbostic #include <stdlib.h> 2757921Sbostic #include <unistd.h> 2857921Sbostic #include <string.h> 2912669Ssam 3038087Sbostic #define DEFNICE 10 3138087Sbostic 3257921Sbostic void usage __P((void)); 3357921Sbostic 3457921Sbostic int 351059Sbill main(argc, argv) 3612669Ssam int argc; 3757921Sbostic char *argv[]; 381059Sbill { 39*66806Sbostic int niceness = DEFNICE; 401059Sbill 4138087Sbostic if (argv[1][0] == '-') 42*66806Sbostic if (argv[1][1] == '-' || isdigit(argv[1][1])) { 4338087Sbostic niceness = atoi(argv[1] + 1); 4438087Sbostic ++argv; 45*66806Sbostic } else 46*66806Sbostic errx(1, "illegal option -- %s", argv[1]); 4738087Sbostic 48*66806Sbostic if (argv[1] == NULL) 4938087Sbostic usage(); 5038087Sbostic 5138087Sbostic errno = 0; 5238087Sbostic niceness += getpriority(PRIO_PROCESS, 0); 53*66806Sbostic if (errno) 54*66806Sbostic err(1, "getpriority"); 55*66806Sbostic if (setpriority(PRIO_PROCESS, 0, niceness)) 56*66806Sbostic err(1, "setpriority"); 571059Sbill execvp(argv[1], &argv[1]); 58*66806Sbostic err(1, "%s", argv[1]); 591059Sbill } 6038087Sbostic 6157921Sbostic void 6238087Sbostic usage() 6338087Sbostic { 6438087Sbostic (void)fprintf(stderr, 6538087Sbostic "nice [ -# ] command [ options ] [ operands ]\n"); 6638087Sbostic exit(1); 6738087Sbostic } 68