-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathionice.c
43 lines (39 loc) · 1.2 KB
/
ionice.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <errno.h>
#include <unistd.h>
void show_usage(char *name) {
fprintf(stderr, "\n");
fprintf(stderr, "%s: set the I/O priority level for a command\n\n", name);
fprintf(stderr, "Usage: %s --high <utility>\n", name);
fprintf(stderr, " or %s --low <utility>\n", name);
fprintf(stderr, " or %s --normal <utility>\n\n", name);
fprintf(stderr, "Copyright 2019 David Cantrell, licenced under the\n");
fprintf(stderr, "GNU General Public Licence version 2\n\n");
}
int main(int argc, char *argv[]) {
if(argc < 3) {
show_usage(argv[0]);
exit(1);
}
if(strncmp("--high", argv[1], 7) == 0) {
setiopolicy_np(
IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_IMPORTANT
);
} else if(strncmp("--normal", argv[1], 9) == 0) {
/* do nothing */
} else if(strncmp("--low", argv[1], 6) == 0) {
setiopolicy_np(
IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE
);
} else {
show_usage(argv[0]);
exit(1);
}
execvp(argv[2], &argv[2]);
perror(argv[2]);
show_usage(argv[0]);
exit(1);
}