Commit | Line | Data |
---|---|---|
bcf1365c | 1 | /* |
c46ced1d KB |
2 | * Copyright (c) 1989, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
ebff467b | 4 | * |
87198c0c | 5 | * %sccs.include.redist.c% |
bcf1365c DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
c46ced1d KB |
9 | static char copyright[] = |
10 | "@(#) Copyright (c) 1989, 1993\n\ | |
11 | The Regents of the University of California. All rights reserved.\n"; | |
ebff467b | 12 | #endif /* not lint */ |
bcf1365c | 13 | |
a8df6a6b | 14 | #ifndef lint |
c46ced1d | 15 | static char sccsid[] = "@(#)nice.c 8.1 (Berkeley) %G%"; |
ebff467b | 16 | #endif /* not lint */ |
a0641931 | 17 | |
876396a1 | 18 | #include <sys/types.h> |
a8df6a6b SL |
19 | #include <sys/time.h> |
20 | #include <sys/resource.h> | |
876396a1 | 21 | |
ebff467b | 22 | #include <ctype.h> |
f7d21c44 KB |
23 | #include <errno.h> |
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
26 | #include <unistd.h> | |
27 | #include <string.h> | |
a8df6a6b | 28 | |
ebff467b KB |
29 | #define DEFNICE 10 |
30 | ||
f7d21c44 KB |
31 | void usage __P((void)); |
32 | ||
33 | int | |
a0641931 | 34 | main(argc, argv) |
a8df6a6b | 35 | int argc; |
f7d21c44 | 36 | char *argv[]; |
a0641931 | 37 | { |
ebff467b | 38 | int niceness; |
a0641931 | 39 | |
ebff467b KB |
40 | niceness = DEFNICE; |
41 | if (argv[1][0] == '-') | |
42 | if (isdigit(argv[1][1])) { | |
43 | niceness = atoi(argv[1] + 1); | |
44 | ++argv; | |
45 | } | |
46 | else { | |
47 | (void)fprintf(stderr, "nice: illegal option -- %c\n", | |
48 | argv[1][1]); | |
49 | usage(); | |
50 | } | |
51 | ||
52 | if (!argv[1]) | |
53 | usage(); | |
54 | ||
55 | errno = 0; | |
56 | niceness += getpriority(PRIO_PROCESS, 0); | |
57 | if (errno) { | |
58 | (void)fprintf(stderr, "nice: getpriority: %s\n", | |
59 | strerror(errno)); | |
a0641931 BJ |
60 | exit(1); |
61 | } | |
ebff467b KB |
62 | if (setpriority(PRIO_PROCESS, 0, niceness)) { |
63 | (void)fprintf(stderr, | |
64 | "nice: setpriority: %s\n", strerror(errno)); | |
a8df6a6b SL |
65 | exit(1); |
66 | } | |
a0641931 | 67 | execvp(argv[1], &argv[1]); |
ebff467b KB |
68 | (void)fprintf(stderr, |
69 | "nice: %s: %s\n", argv[1], strerror(errno)); | |
70 | exit(1); | |
71 | } | |
72 | ||
f7d21c44 | 73 | void |
ebff467b KB |
74 | usage() |
75 | { | |
76 | (void)fprintf(stderr, | |
77 | "nice [ -# ] command [ options ] [ operands ]\n"); | |
a0641931 BJ |
78 | exit(1); |
79 | } |