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