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.3 (Berkeley) 04/28/95";
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
main(argc,argv)35 main(argc, argv)
36 int argc;
37 char *argv[];
38 {
39 int niceness = DEFNICE;
40
41 if (argv[1] == NULL)
42 usage();
43 if (argv[1][0] == '-')
44 if (argv[1][1] == '-' || isdigit(argv[1][1])) {
45 niceness = atoi(argv[1] + 1);
46 ++argv;
47 if (argv[1] == NULL)
48 usage();
49 } else
50 errx(1, "illegal option -- %s", argv[1]);
51
52 errno = 0;
53 niceness += getpriority(PRIO_PROCESS, 0);
54 if (errno)
55 err(1, "getpriority");
56 if (setpriority(PRIO_PROCESS, 0, niceness))
57 err(1, "setpriority");
58 execvp(argv[1], &argv[1]);
59 err(1, "%s", argv[1]);
60 }
61
62 void
usage()63 usage()
64 {
65 (void)fprintf(stderr,
66 "nice [ -# ] command [ options ] [ operands ]\n");
67 exit(1);
68 }
69