119845Sdist /* 2*38087Sbostic * Copyright (c) 1989 The Regents of the University of California. 3*38087Sbostic * All rights reserved. 4*38087Sbostic * 5*38087Sbostic * Redistribution and use in source and binary forms are permitted 6*38087Sbostic * provided that the above copyright notice and this paragraph are 7*38087Sbostic * duplicated in all such forms and that any documentation, 8*38087Sbostic * advertising materials, and other materials related to such 9*38087Sbostic * distribution and use acknowledge that the software was developed 10*38087Sbostic * by the University of California, Berkeley. The name of the 11*38087Sbostic * University may not be used to endorse or promote products derived 12*38087Sbostic * from this software without specific prior written permission. 13*38087Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*38087Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*38087Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1619845Sdist */ 1719845Sdist 1812669Ssam #ifndef lint 1919845Sdist char copyright[] = 20*38087Sbostic "@(#) Copyright (c) 1989 The Regents of the University of California.\n\ 2119845Sdist All rights reserved.\n"; 22*38087Sbostic #endif /* not lint */ 231059Sbill 2419845Sdist #ifndef lint 25*38087Sbostic static char sccsid[] = "@(#)nice.c 5.3 (Berkeley) 05/20/89"; 26*38087Sbostic #endif /* not lint */ 2719845Sdist 2812669Ssam #include <sys/time.h> 2912669Ssam #include <sys/resource.h> 30*38087Sbostic #include <stdio.h> 31*38087Sbostic #include <ctype.h> 3212669Ssam 33*38087Sbostic #define DEFNICE 10 34*38087Sbostic 35*38087Sbostic /* ARGSUSED */ 361059Sbill main(argc, argv) 3712669Ssam int argc; 38*38087Sbostic char **argv; 391059Sbill { 40*38087Sbostic extern int errno; 41*38087Sbostic int niceness; 42*38087Sbostic char *strerror(); 431059Sbill 44*38087Sbostic niceness = DEFNICE; 45*38087Sbostic if (argv[1][0] == '-') 46*38087Sbostic if (isdigit(argv[1][1])) { 47*38087Sbostic niceness = atoi(argv[1] + 1); 48*38087Sbostic ++argv; 49*38087Sbostic } 50*38087Sbostic else { 51*38087Sbostic (void)fprintf(stderr, "nice: illegal option -- %c\n", 52*38087Sbostic argv[1][1]); 53*38087Sbostic usage(); 54*38087Sbostic } 55*38087Sbostic 56*38087Sbostic if (!argv[1]) 57*38087Sbostic usage(); 58*38087Sbostic 59*38087Sbostic errno = 0; 60*38087Sbostic niceness += getpriority(PRIO_PROCESS, 0); 61*38087Sbostic if (errno) { 62*38087Sbostic (void)fprintf(stderr, "nice: getpriority: %s\n", 63*38087Sbostic strerror(errno)); 641059Sbill exit(1); 651059Sbill } 66*38087Sbostic if (setpriority(PRIO_PROCESS, 0, niceness)) { 67*38087Sbostic (void)fprintf(stderr, 68*38087Sbostic "nice: setpriority: %s\n", strerror(errno)); 6912669Ssam exit(1); 7012669Ssam } 711059Sbill execvp(argv[1], &argv[1]); 72*38087Sbostic (void)fprintf(stderr, 73*38087Sbostic "nice: %s: %s\n", argv[1], strerror(errno)); 741059Sbill exit(1); 751059Sbill } 76*38087Sbostic 77*38087Sbostic usage() 78*38087Sbostic { 79*38087Sbostic (void)fprintf(stderr, 80*38087Sbostic "nice [ -# ] command [ options ] [ operands ]\n"); 81*38087Sbostic exit(1); 82*38087Sbostic } 83