119845Sdist /* 238087Sbostic * Copyright (c) 1989 The Regents of the University of California. 338087Sbostic * All rights reserved. 438087Sbostic * 5*42755Sbostic * %sccs.include.redist.c% 619845Sdist */ 719845Sdist 812669Ssam #ifndef lint 919845Sdist char copyright[] = 1038087Sbostic "@(#) Copyright (c) 1989 The Regents of the University of California.\n\ 1119845Sdist All rights reserved.\n"; 1238087Sbostic #endif /* not lint */ 131059Sbill 1419845Sdist #ifndef lint 15*42755Sbostic static char sccsid[] = "@(#)nice.c 5.4 (Berkeley) 06/01/90"; 1638087Sbostic #endif /* not lint */ 1719845Sdist 1812669Ssam #include <sys/time.h> 1912669Ssam #include <sys/resource.h> 2038087Sbostic #include <stdio.h> 2138087Sbostic #include <ctype.h> 2212669Ssam 2338087Sbostic #define DEFNICE 10 2438087Sbostic 2538087Sbostic /* ARGSUSED */ 261059Sbill main(argc, argv) 2712669Ssam int argc; 2838087Sbostic char **argv; 291059Sbill { 3038087Sbostic extern int errno; 3138087Sbostic int niceness; 3238087Sbostic char *strerror(); 331059Sbill 3438087Sbostic niceness = DEFNICE; 3538087Sbostic if (argv[1][0] == '-') 3638087Sbostic if (isdigit(argv[1][1])) { 3738087Sbostic niceness = atoi(argv[1] + 1); 3838087Sbostic ++argv; 3938087Sbostic } 4038087Sbostic else { 4138087Sbostic (void)fprintf(stderr, "nice: illegal option -- %c\n", 4238087Sbostic argv[1][1]); 4338087Sbostic usage(); 4438087Sbostic } 4538087Sbostic 4638087Sbostic if (!argv[1]) 4738087Sbostic usage(); 4838087Sbostic 4938087Sbostic errno = 0; 5038087Sbostic niceness += getpriority(PRIO_PROCESS, 0); 5138087Sbostic if (errno) { 5238087Sbostic (void)fprintf(stderr, "nice: getpriority: %s\n", 5338087Sbostic strerror(errno)); 541059Sbill exit(1); 551059Sbill } 5638087Sbostic if (setpriority(PRIO_PROCESS, 0, niceness)) { 5738087Sbostic (void)fprintf(stderr, 5838087Sbostic "nice: setpriority: %s\n", strerror(errno)); 5912669Ssam exit(1); 6012669Ssam } 611059Sbill execvp(argv[1], &argv[1]); 6238087Sbostic (void)fprintf(stderr, 6338087Sbostic "nice: %s: %s\n", argv[1], strerror(errno)); 641059Sbill exit(1); 651059Sbill } 6638087Sbostic 6738087Sbostic usage() 6838087Sbostic { 6938087Sbostic (void)fprintf(stderr, 7038087Sbostic "nice [ -# ] command [ options ] [ operands ]\n"); 7138087Sbostic exit(1); 7238087Sbostic } 73