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 |
87198c0c | 15 | static char sccsid[] = "@(#)nice.c 5.4 (Berkeley) %G%"; |
ebff467b | 16 | #endif /* not lint */ |
a0641931 | 17 | |
a8df6a6b SL |
18 | #include <sys/time.h> |
19 | #include <sys/resource.h> | |
ebff467b KB |
20 | #include <stdio.h> |
21 | #include <ctype.h> | |
a8df6a6b | 22 | |
ebff467b KB |
23 | #define DEFNICE 10 |
24 | ||
25 | /* ARGSUSED */ | |
a0641931 | 26 | main(argc, argv) |
a8df6a6b | 27 | int argc; |
ebff467b | 28 | char **argv; |
a0641931 | 29 | { |
ebff467b KB |
30 | extern int errno; |
31 | int niceness; | |
32 | char *strerror(); | |
a0641931 | 33 | |
ebff467b KB |
34 | niceness = DEFNICE; |
35 | if (argv[1][0] == '-') | |
36 | if (isdigit(argv[1][1])) { | |
37 | niceness = atoi(argv[1] + 1); | |
38 | ++argv; | |
39 | } | |
40 | else { | |
41 | (void)fprintf(stderr, "nice: illegal option -- %c\n", | |
42 | argv[1][1]); | |
43 | usage(); | |
44 | } | |
45 | ||
46 | if (!argv[1]) | |
47 | usage(); | |
48 | ||
49 | errno = 0; | |
50 | niceness += getpriority(PRIO_PROCESS, 0); | |
51 | if (errno) { | |
52 | (void)fprintf(stderr, "nice: getpriority: %s\n", | |
53 | strerror(errno)); | |
a0641931 BJ |
54 | exit(1); |
55 | } | |
ebff467b KB |
56 | if (setpriority(PRIO_PROCESS, 0, niceness)) { |
57 | (void)fprintf(stderr, | |
58 | "nice: setpriority: %s\n", strerror(errno)); | |
a8df6a6b SL |
59 | exit(1); |
60 | } | |
a0641931 | 61 | execvp(argv[1], &argv[1]); |
ebff467b KB |
62 | (void)fprintf(stderr, |
63 | "nice: %s: %s\n", argv[1], strerror(errno)); | |
64 | exit(1); | |
65 | } | |
66 | ||
67 | usage() | |
68 | { | |
69 | (void)fprintf(stderr, | |
70 | "nice [ -# ] command [ options ] [ operands ]\n"); | |
a0641931 BJ |
71 | exit(1); |
72 | } |