nice.c - sbase - suckless unix tools | |
git clone git://git.suckless.org/sbase | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
nice.c (898B) | |
--- | |
1 /* See LICENSE file for copyright and license details. */ | |
2 #include <sys/resource.h> | |
3 | |
4 #include <errno.h> | |
5 #include <stdlib.h> | |
6 #include <unistd.h> | |
7 | |
8 #include "util.h" | |
9 | |
10 #ifndef PRIO_MIN | |
11 #define PRIO_MIN -NZERO | |
12 #endif | |
13 | |
14 #ifndef PRIO_MAX | |
15 #define PRIO_MAX (NZERO-1) | |
16 #endif | |
17 | |
18 static void | |
19 usage(void) | |
20 { | |
21 eprintf("usage: %s [-n inc] cmd [arg ...]\n", argv0); | |
22 } | |
23 | |
24 int | |
25 main(int argc, char *argv[]) | |
26 { | |
27 int val = 10, r, savederrno; | |
28 | |
29 ARGBEGIN { | |
30 case 'n': | |
31 val = estrtonum(EARGF(usage()), PRIO_MIN, PRIO_MAX); | |
32 break; | |
33 default: | |
34 usage(); | |
35 break; | |
36 } ARGEND | |
37 | |
38 if (!argc) | |
39 usage(); | |
40 | |
41 errno = 0; | |
42 r = getpriority(PRIO_PROCESS, 0); | |
43 if (errno) | |
44 weprintf("getpriority:"); | |
45 else | |
46 val += r; | |
47 LIMIT(val, PRIO_MIN, PRIO_MAX); | |
48 if (setpriority(PRIO_PROCESS, 0, val) < 0) | |
49 weprintf("setpriority:"); | |
50 | |
51 execvp(argv[0], argv); | |
52 savederrno = errno; | |
53 weprintf("execvp %s:", argv[0]); | |
54 | |
55 _exit(126 + (savederrno == ENOENT)); | |
56 } |