119845Sdist /* 238087Sbostic * Copyright (c) 1989 The Regents of the University of California. 338087Sbostic * All rights reserved. 438087Sbostic * 542755Sbostic * %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*54037Sbostic static char sccsid[] = "@(#)nice.c 5.5 (Berkeley) 06/18/92"; 1638087Sbostic #endif /* not lint */ 1719845Sdist 18*54037Sbostic #include <sys/types.h> 1912669Ssam #include <sys/time.h> 2012669Ssam #include <sys/resource.h> 21*54037Sbostic 2238087Sbostic #include <stdio.h> 2338087Sbostic #include <ctype.h> 2412669Ssam 2538087Sbostic #define DEFNICE 10 2638087Sbostic 2738087Sbostic /* ARGSUSED */ 281059Sbill main(argc, argv) 2912669Ssam int argc; 3038087Sbostic char **argv; 311059Sbill { 3238087Sbostic extern int errno; 3338087Sbostic int niceness; 3438087Sbostic char *strerror(); 351059Sbill 3638087Sbostic niceness = DEFNICE; 3738087Sbostic if (argv[1][0] == '-') 3838087Sbostic if (isdigit(argv[1][1])) { 3938087Sbostic niceness = atoi(argv[1] + 1); 4038087Sbostic ++argv; 4138087Sbostic } 4238087Sbostic else { 4338087Sbostic (void)fprintf(stderr, "nice: illegal option -- %c\n", 4438087Sbostic argv[1][1]); 4538087Sbostic usage(); 4638087Sbostic } 4738087Sbostic 4838087Sbostic if (!argv[1]) 4938087Sbostic usage(); 5038087Sbostic 5138087Sbostic errno = 0; 5238087Sbostic niceness += getpriority(PRIO_PROCESS, 0); 5338087Sbostic if (errno) { 5438087Sbostic (void)fprintf(stderr, "nice: getpriority: %s\n", 5538087Sbostic strerror(errno)); 561059Sbill exit(1); 571059Sbill } 5838087Sbostic if (setpriority(PRIO_PROCESS, 0, niceness)) { 5938087Sbostic (void)fprintf(stderr, 6038087Sbostic "nice: setpriority: %s\n", strerror(errno)); 6112669Ssam exit(1); 6212669Ssam } 631059Sbill execvp(argv[1], &argv[1]); 6438087Sbostic (void)fprintf(stderr, 6538087Sbostic "nice: %s: %s\n", argv[1], strerror(errno)); 661059Sbill exit(1); 671059Sbill } 6838087Sbostic 6938087Sbostic usage() 7038087Sbostic { 7138087Sbostic (void)fprintf(stderr, 7238087Sbostic "nice [ -# ] command [ options ] [ operands ]\n"); 7338087Sbostic exit(1); 7438087Sbostic } 75