2024-07-01 10:23:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int oldp = getpriority(PRIO_PROCESS, 0);
|
|
|
|
int adj = 10;
|
|
|
|
|
|
|
|
int opt;
|
|
|
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'n':
|
|
|
|
adj = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-07-03 14:22:50 +00:00
|
|
|
puts("nice [n] [cmd] [arg1] [arg2]\n\t-n N Add N to the niceness");
|
2024-07-01 10:23:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argv += optind;
|
|
|
|
argc -= optind;
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
printf("%d\n", oldp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setpriority(PRIO_PROCESS, 0, oldp + adj) < 0) {
|
|
|
|
fprintf(stderr, "nice: %s\n", strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
execvp(argv[0], argv);
|
|
|
|
fprintf(stderr, "nice: %s: %s\n", argv[0], strerror(errno));
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|