44 lines
762 B
C
44 lines
762 B
C
#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:
|
|
puts("nice [n] [cmd] [arg1] [arg2]\n\t-n N Add N to the niceness");
|
|
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;
|
|
}
|